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:
A, B, C, K = map(int, input().split())
k = K
a = min(A, k)
k -= a
b = min(B, k)
k -= b
c = min(C, k)
print(a-c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,y,z,k=map(int,input().split())
s=min(k,x)
k=k-s
if(k>0):
    k=k-min(k,y)
if(k>0):
    f=min(k,z)
    s=s-f
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
if a+b >= k:
  if a <= k:
    print(a)
  else:
    print(k)
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())
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())

# ans = [1] * a + [0] * b + [-1] * c
# print(sum(ans[:k]))
if a > k:
    print(k)
elif a + b >= k:
    print(a)
else:
    print(a - (k - (a + b)))

Submission status: Accepted

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

Submission status: Accepted

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

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())
print(1*min(A,K)-1*max(0,K-A-B))

Submission status: Accepted

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

ans=1*min(A,K)
K=max(0,K-A-B)
print(ans-(1*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 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 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())
ans = 0

if K<A:
  ans+=K
  print(ans)
  exit()
else:
  ans+=A
  K-=A
  
if K<B:
  print(ans)
  exit()
else:
  K-=B
  
if K<C:
  ans+=K*(-1)
  print(ans)
else:
  ans+=C*(-1)
  print(ans)

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = (int(i) for i in input().split())
    ans = min(a, k)
    k -= a
    if k <= 0:
        print(ans)
        return
    k -= b
    if k <= 0:
        print(ans)
        return
    print(ans - k)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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(A - (K - A - B))

Submission status: Accepted

Solution code:
def solve():
    A,B,C,K = [int(i) for i in input().split()]
    ans = 0
    ans += min(A, K)
    if K-A-B > 0:
        ans -= (K-A-B)
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

print(max)

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 -1*(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(A+(K-A-B)*-1)

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:
# Easy Liniear Programming
A,B,C,K = map(int,input().split())
ans = min(A,K)*1 + max(0, K-A)*0 + max(0, K-A-B)*(-1)
print(ans)

Submission status: Accepted

Solution code:
def main():
    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)))


if __name__ == '__main__':
    main()

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 = list(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=list(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())

if K<=A+B:
    print(min(A,K))
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(a -1*(k-a-b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import math

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

Submission status: Accepted

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

    positive = min(k, a)
    zero = min(k - positive, b)
    negative = min(k - positive - zero, c)

    max = positive - negative
    print(max)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
  ans = k
elif a < k and 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())

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

Submission status: Accepted

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

s = 0

mn = min(A, K)
s += mn 
K -= mn

mn = min(B, K)
K -= mn

mn = min(C, K)
s -=mn
K -= mn

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s = list(map(int,input().strip().split()))
    k = s[3]
    r = 0
    if s[0] <= k:
        r += 1 * s[0]
        k -= s[0]
    else:
        r += 1 * k
        print(r)
        return
    
    if (k-s[1]) <=0:
        print(r)
        return
    
    if s[2] <= (k-s[1]):
        r += (-1)*s[2]
    else:
        r += (-1) * (k-s[1])
    
    print(r)
    return
    
    
main()

Submission status: Accepted

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

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

Submission status: Accepted

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

    ra = min(k, a)
    k -= ra
    k -= b
    rc = 0 if k <= 0 else -(min(k, c))
    print(ra + rc)


if __name__ == '__main__':
    Qb()

Submission status: Accepted

Solution code:
def main():
  a,b,c,k = list(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)))
  else:
    print(a-c)
  
main()

Submission status: Accepted

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

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:
    print(A-(K-A-B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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)
else:
  print(a-(k-(a+b)))

Submission status: Accepted

Solution code:
a, b, c, k = 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:
if __name__ == '__main__':
    a, b, c, k = map(int, input().split())
    
    if k <= a:
        print(k)
    elif a < k and k <= (a+b):
        print(a)
    else:
        print(a - (k-a-b))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    a, b, c, k = map(int, input().split())
    r = min(k, a)
    k -= a
    if k > 0:
        k -= b
        if k > 0:
            r -= k
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = 0
if K <= A:
    res = K
elif K <= B:
    res = A
else:
    res = A - (K - A - B)

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k=map(int,open(0).read().split())

if k<=a+b:
    print(min(a,k))
else:
    cntc=k-a-b
    print(a-cntc)

Submission status: Accepted

Solution code:
A, B, C, K = [int(i) for i in input().split(' ')]
print(min(A, K) - max(K - B - A, 0))

Submission status: Accepted

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

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

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

ans+=(-1)*k
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
 
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

a, b, c, k = Is()

a = min(a, k)
k -= a

b = min(b, k)
k -= b

c = min(c, k)
k -= c

print(a-c)

Submission status: Accepted

Solution code:
*abc, k = map(int, input().split())
n = [0] * 3
for i, v in enumerate(abc):
    if k >= v:
        n[i] = v
        k -= v
    else:
        n[i] = k
        break

print(n[0] + n[2] * -1)

Submission status: Accepted

Solution code:
*abc, k = list(map(int, input().split()))
n = [0] * 3
ans = 0
for i, v in enumerate(abc):
    if k >= v:
        n[i] = v
        k -= v
    else:
        n[i] = k
        break

print(n[0] + n[1] * 0 + n[2] * -1)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")

a,b,c,k=LI()
if k<=a:
    ans = k
elif k<=a+b:
    ans = a
elif k>a+b:
    # a - cの枚数(k-(a+b))
    ans = a - (k - (a + b))
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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())
if a>=k:
    print(k)
elif a<k and a+b>=k:
    print(a)
else:
    d=k-a-b
    print(a-d)

Submission status: Accepted

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

if A >= K:
    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 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 = list(map(int, input().split()))

score = 0
if K <= A:
    score = K
    print(score)
    exit()

score += A
K -= A
if K <= B:
    print(score)
    exit()

K -= B
print(score - K)

Submission status: Accepted

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

import sys

ans = 0
if a != 0 and a >= k:
    # a = 1
    print(k)
    sys.exit()
elif a != 0:
    ans += a
    k -= a

if b != 0 and b >= k:
    print(ans)
    sys.exit()
elif b != 0:
    k -= b

ans += k * -1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    import sys

    input = sys.stdin.readline

    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))


if __name__ == '__main__':
    main()

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)
elif (k > a) and (k - a > b):
    print(a - (k-a-b))

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
ans = 0
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 = list(map(lambda x : int(x), input().split(" ")))
if A >= K:
  print(K)
elif A + B >= K:
  print(A)
else:
  print(2 * A + B - K)

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())
print(k if k<a else(a if a+b>=k else 2*a-k+b))

Submission status: Accepted

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

def some(a,b,c,k):
    x_a = min(k, a)
    k -= x_a
    x_b = min(k, b)
    k -= x_b
    x_c = k
    print(x_a*1+x_b*0+x_c*-1)

some(a,b,c,k)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
if k > a:
    cnt += a
    if k-a > b:
        if k-a-b > 0:
            cnt -= k-a-b
else:
    cnt += k

print(cnt)

Submission status: Accepted

Solution code:
def solve():
  A, B, C, K = map(int, input().split())
  ans = min(A,K)-max(0,K-A-B)
  return ans
print(solve())

Submission status: Accepted

Solution code:
IN = [i for i in map(int,input().split())]
K = IN[3]
A = min(IN[0],K)
B = min(IN[1], K -A)
C = min(IN[2],K -A- B)
print(A*1+B*0+C*(-1))

Submission status: Accepted

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

if a-k <= 0:
    a_ans = a
    k = k-a
else:
    a_ans = k
    k=0
if b-k <= 0 and k>0:
    b_ans = b
    k = k-b
else:
    b_ans = k
    k=0
if c-k <= 0 and k>0:
    c_ans = c
    k = k-b
else:
    c_ans = k
    
ans = a_ans*1 + b_ans*0 + c_ans*(-1)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    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)))


if __name__ == '__main__':
    main()

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 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 A <= K <= A + B:
    print(A)
else:
    print(A - (K - A - B))

Submission status: Accepted

Solution code:
a, b, c, k = map(int, raw_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(a - (k - a - b))

Submission status: Accepted

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

Submission status: Accepted

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

    if K<A+B:
        if K<A:
            print(K)
            return
        print(A)
        return
    print(A-(K-A-B))
    return

score()

Submission status: Accepted

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

def main():
    a,b,c,k = map(int, input().split())
    if a >= k:
        print(k)
    else: # aより多い
        k -= a
        if b >= k:
            print(a)
        else:
            k -= b
            print(a-k)


if __name__=="__main__":
    main()

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 A  >= K:
    print(K)

elif A + B >= K:
    print(A)

else:
    c = K - A - B
    print(A-c)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
ans = 0
ans += min(a, k)
k = max(k-a,0)
k = max(k-b,0)
ans -= min(c, k)
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:
a,b,c,k=map(int,input().split())

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

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())
D = A + B
if D >= K:
    print(min(K,A))
else:
    K -= D
    print(A-K)

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(2 * A + B - K)

Submission status: Accepted

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

Submission status: Accepted

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

score = 0

if A<K:
    K -= A
    score += A
else:
    score += K
    print(score)
    exit()

if B<K:
    K -= B
else:
    print(score)
    exit()

score -= min(K,C)
print(score)

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(2*A-K+B)

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
    print(ans)
    exit()
if K>B:
    K-=B
else:
    print(ans)
    exit()
ans-=K
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
readline = sys.stdin.readline

a,b,c,K = map(int,readline().split())

print(min(a,K) - max(K - (a + b),0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# KをA,B,Cの順に割り振る
a = min(A, K)
K -= a

b = min(B, K)
K -= b

c = min(C, K)

print(1 * a + -1 * c)

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(a - (k - a - b))

Submission status: Accepted

Solution code:
A,B,C,K= map(int,input().split())
s0m = 0
x = max(0,A-K)
if x == 0 :
    s0m =+ A
    K = K-A
else :
    s0m =+ K
    K=0
if K==0 :
    print (s0m)
else :
    y = max (0 ,B-K)
    if y == 0 :
        K=K-B
    else :
        K = 0
    if K == 0:
        print (s0m)
    else:
        z = max (0,C-K)
        if z== 0 :
            s0m = s0m - C
        else :
            s0m -=K
        print (s0m)

Submission status: Accepted

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

ans = 0

ans += min(a,k)
k -= min(a,k)
ans += min(b,k) * 0
k -= min(b,k)
ans += min(c,k) * -1
k -= min(c,k)

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(2*a+b-k)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

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:
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

A, B, C, K = inpl()
xa = min(K, A)
K -= xa
xb = min(K, B)
K -= xb
xc = K
print(xa-xc)


# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Submission status: Accepted

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

def main():

    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 + (-1 * (K - A - B))

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A,B,C,K = list(map(int,input().split()))
print(max(min(K,A),0) - max(min(K-(A+B),C),0))

Submission status: Accepted

Solution code:
# abc167_b.py
# https://atcoder.jp/contests/abc167/tasks/abc167_b

# B - Easy Linear Programming /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 1が書かれたカードが A 枚、0 が書かれたカードが B 枚、 −1 が書かれたカードが C枚あります。
# これらのカードから、ちょうど K枚を選んで取るとき、取ったカードに書かれた数の和として、 ありうる値の最大値はいくつですか。

# 制約
#     入力は全て整数である。
#     0≤A,B,C
#     1≤K≤A+B+C≤2×109

# 入力
# 入力は以下の形式で標準入力から与えられる。
# A B C K

# 出力
# 和としてありうる値の最大値を出力せよ。

# 入力例 1
# 2 1 1 3

# 出力例 1
# 2

# 1が書かれたカードを 2 枚、0 が書かれたカードを 1 枚取ることを考えます。 
# このときカードに書かれた数の和は 2になり、和としてありうる値の最大値になります。

# 入力例 2
# 1 2 3 4

# 出力例 2
# 0

# 入力例 3
# 2000000000 0 0 2000000000

# 出力例 3
# 2000000000


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    A, B, C, K = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

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

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2 1 1 3']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['1 2 3 4']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['2000000000 0 0 2000000000']
        lines_export = [2000000000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = min(A, K)
K -= a
b = min(B, K)
K -= b
c = min(C, K)

print(a-c)

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)))