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

l = []
ans = 0

if a >= k:
    print(k)

elif (a+b) >= k:
    print(a)

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

Submission status: Accepted

Solution code:
# B
# Easy Linear Programming

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

ans = 0
flag = False

if a >= k:
    ans = k
else:
    ans = a
    tmp = k - a
    if b < tmp:
        tmp = tmp - b
        ans = ans - tmp
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    A,B,C,K = map(int,input().split())
    if K<=A:
        print(K)
    else:
        summ=A
        K-=A
        if K>B:
            K-=B
            if K>0:
                summ-=K
        print(summ)
if __name__=='__main__':
    main()

Submission status: Accepted

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

if A>=K:
    point=K
    #print("1st")
    
elif A+B>=K:
    point=A
    
else:
    point=A+(-1)*(K-A-B)
    
    
print(point)

Submission status: Accepted

Solution code:
a, b, c, k = [int(i) for i in 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:
A,B,C,K = map(int,input().split())
if K < A:
  print(K)
elif K < (A+B):
  print(A)
else:# K > (A+B):
  print(A - (K-A-B))

Submission status: Accepted

Solution code:
import sys
import math
import itertools

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

  if a > k:
    r = k
    k = 0
  else:
    r = a
    k = k - a

  if b > k:
    k = 0
  else:
    k = k - b

  r -= k
    

  print(r)
    

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    [a,b,c,k] = [int(i) for i in 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:
        k-=c
        ans -= c
    else:
        ans -= k
        k = 0
    
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

if k >= a:
    ans += a
    k -= a
    if k >= b:
        k -= b
        if k >= c:
            ans -= c
            k -= c
        else:
            ans -= k
else:
    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)
elif 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+B >= K:
  print(min(A, K))
else:
  print(A - (K - A - B))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
if k <= a:
    print(k)
else:
    if 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 = [int(i) for i in 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 = list(map(int, input().split()))
tmp = K-A
if tmp>0:
  tmp -= B
  if tmp>0:
    ans = 1*A-1*(K-A-B)
  else:
    ans = 1*A
else:
  ans = 1*K
print(ans)

Submission status: Accepted

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

arieru_max = 0
selected = 0

# 1の枚数がK以下
if A <= K:
    arieru_max += A
    selected += A

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

        if C <= (K - A - B):
            arieru_max -= C
        else:
            arieru_max -= (K - A - B)

# 1の枚数がKを超える
else:
    arieru_max = K

print(arieru_max)

Submission status: Accepted

Solution code:
import sys

if __name__ == '__main__':
    p,z,n,k = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))

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

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()
if k-b>=0:
    ans += 0
    k-=b
else:
    print(ans)
    exit()
if k-c >=0:
    ans += (-1)*c
    print(ans)
    exit()
else:
    ans += (-1)*k
    print(ans)

Submission status: Accepted

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

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

if k:
    k -= b

if k > 0:
    ans -= k

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

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:
import sys
A, B, C, K = map(int, input().split())
N = 0
if K - A < 0:
    print(K)
    sys.exit()
else:
    N = A
    K = K - A
if K - B < 0:
    print(N)
    sys.exit()
else:
    K = K - B
print(N - K)

Submission status: Accepted

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

Submission status: Accepted

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

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(a,b,c,k):
    res = 0
    if k < a:
        res = k
    elif a <= k < a+b:
        res = a
    elif a+b <= k:
        res = a - (k - (a + b))
    return res

a,b,c,k = mi()
print(main(a,b,c,k))

Submission status: Accepted

Solution code:
A, B, C, k = map(int, input().split())
if A > k:
    print(k)
else:
    r = A
    _k = k - A - B

    if _k > 0:
        r -= _k

    print(r)

Submission status: Accepted

Solution code:
import sys
import math
from  collections import defaultdict

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

def solve(test):
	a, b, c, k = map(int, input().split())
	ans = min(k, a)
	k -= a + b
	if k > 0:
		ans -= k
	print(ans)




if __name__ == "__main__":
	test_cases = 1
	for t in range(1, test_cases + 1):
		solve(t)

Submission status: Accepted

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

max_num()

Submission status: Accepted

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

res = 0
if k >= a:
    res = a
    k = k - a
    if k >= b:
        k = k - b
        if k >= 0:
            res = res - k
else:
    res = k

print(res)

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=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
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,c,k=map(int, input().split())
    l=[]
    if k<=a:
        print(k)
    elif a<k<=a+b:
        print(a)
    else:
        print(a-(k-(a+b)))
resolve()

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)
elif A+B+C >= K:
    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:
    print(a-(k-a-b))

Submission status: Accepted

Solution code:
a,b,c,k = [int(p) for p in 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:
    ans = K
elif A+B >= K:
    ans = A
else:
    ans = A - (K-A-B)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections

def solve(A,B,C,K):
    ans = 0
    while K != 0:
        if( A != 0):
            if(K < A):
                ans += K
                break
            else:
                ans+=A
                K -= A
                A = 0
        elif(B != 0):
            if(K < B):
                break
            else:
                K -= B
                B = 0
        else:
            if(K < C):
                ans -= K
                break
            else:
                ans -= C
                K -= C
                C = 0
    return ans
def main():
    A,B,C,K =map(int,input().split())
    # solve()
    print(solve(A,B,C,K))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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 :
    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 A>= K:
    print(K*1)
    exit()
    
elif A < K and A+B >= K:
    print(A*1)
    exit()
    
elif A+B < K and A+B+C >= K:
    print(A*1 + (K-A-B)*(-1))

Submission status: Accepted

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

if A < K and K > 0:
    ans += A
    K -= A
elif A >= K and K > 0:
    ans += K
    K = 0

if B < K and K > 0:
    K -= B
elif B >= K and K > 0:
    K = 0

if C < K and K > 0:
    ans -= C
    K -= C
elif C >= K and K > 0:
    ans -= K
    K = 0

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = list(map(int,input().split()))
a = n[0]
b = n[1]
c = n[2]
k = n[3]
an = 0
if a>=k:
  an=k
elif a+b>=k:
  an=a
else:
  an=a-(k-a-b)
print(an)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

ans += min(A, K)

if (A+B)>=K:
    print(ans)
    sys.exit()

K -= (A+B)

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())
sum = 0

if K > A:
    K -= A
    sum = A
else:
    print(K)
    exit()

if K > B:
    K -= B
else:
    print(sum)
    exit()

sum -= K
print(sum)

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 = list(map(int, input().split()))
d = []
if k <= a:
    print(k)
elif a < k < b:
    print(a)
else:
    print(2 * a + b - k)

Submission status: Accepted

Solution code:
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 -= 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 k <= a: 
  print(k)
elif k <= a+b:
  print(a)
else:
  print(2*a+b-k)

Submission status: Accepted

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

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

    print(ans)


resolve()

Submission status: Accepted

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

s = [a, a+b, a+b+c]
ans = [a, a, a-c]

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



ans = 0

if k <= a:
    ans = k
elif 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())
#lst = [1]*a + [0]*b + [-1]*c

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,K=(int(x) for x in input().split())
if(A>=K):
    print(K)
elif(A+B>=K):
    print(A)
elif(A+B+C>=K):
    print(A-(K-(A+B)))

Submission status: Accepted

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

d = 0

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

print(d)

Submission status: Accepted

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

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

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+b+c-K+(a-c))

Submission status: Accepted

Solution code:
a, b, c, k = [int(i) for i in input().split()]

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

Submission status: Accepted

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

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

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

if c >= k:
    ans -= k
    print(ans)
    exit()
else:
    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(k-b)
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 K<=A+B:
    print(A)
else:
    print(2*A+B-K)

Submission status: Accepted

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

A = ABCK[0]
B = ABCK[1]
C = ABCK[2]
K = ABCK[3]
sums = 0
if (K - A <= 0):
    sums += K
else:
    K = K-A
    sums += A
    if(K-B <= 0):
        sums += 0
    else:
        K = K-B
        sums += K*(-1)

print(sums)

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())
if k<=a: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())
ans=0
ans=K
K-=A
def chk(k):
    if k>0:
        return True
    else:
        return False

if not chk(K):
    print(ans)
    exit()
ans=A
K-=B
if not chk(K):
    print(ans)
    exit()

ans=ans-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:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

a, b, c, k = nm()
ans = min(a, k) - max(k - a- b, 0)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)


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

    ans = 0
    
    if A > K:
        ans += K * 1
        K = 0
    else:
        ans += A
        K = K - A
        if B > K:
            ans += K * 0
            K = K - B
        else:
            K = K - B
            if C > K:
                ans -= K
            else:
                ans -= C

    print(ans)

                
        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x=input().split(" ")
a=int(x[0])
b=int(x[1])
c=int(x[2])
number=int(x[3])
if number<=a:
    print(number)
elif number<=a+b:
    print(a)
else:
    print(2*a+b-number)

Submission status: Accepted

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

print (ans)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

a,b,c,k = myinput()

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

Submission status: Accepted

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

Submission status: Accepted

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

if K - A <= 0:
  ans = K
elif K - A > 0:
  ans += A
  if K - B > 0:
    ans -= (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 + b >= k:
    print(a)
else:
    hiku = k - a - b
    print(a - hiku)

Submission status: Accepted

Solution code:
import sys
import os

def file_input():
    f = open('ABC167/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # int(input())
    A,B,C,K=map(int, input().split())

    sum=0
    if K>A:
        sum+=A
        K-=A
        if K>B:
            K-=B
            sum-=K        
    else:
        sum+=K

    print(sum)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


# a = [1]*A
# b = [0]*B
# c = [-1]*C
# u = a + b + c
# u.sort(reverse=True)
ans = 0
if K <= A:
    ans = K
if K > A and K <= A + B:
    ans = A
if K > A + B:
    ans = A - (K-A - B)


# ans = 0
# for i in range(K):
#     ans += u[i]

print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = [int(v) for v in input().strip().split(" ")]


if K <= A:
    result = K
elif K > A:
    K = K - A
    result = A
    if K <= B:
        result = result
    else:
        K = K - B
        result = result - K

print(result)

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

Submission status: Accepted

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

Submission status: Accepted

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

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) * (-1)))

Submission status: Accepted

Solution code:
import math
A,B,C,K = map(int,input().split())
count = 0
ans =0
if A>=K:
  ans = K
  print(K)
  exit()
elif A<K:
  count = K-A
  ans += A
  if count <= B:
    print(ans)
    exit()
  elif count > B:
    count = count-B
    ans += (-1)*count
    print(ans)
    exit()

Submission status: Accepted

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

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

tmp = A - K
if tmp >= 0:
    print(K)
    exit(0)
tmp = (A + B) - K
if tmp >= 0:
    print(A)
    exit(0)

print(A + tmp)

Submission status: Accepted

Solution code:
import sys

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

if k <= b :
    print(ans)
    sys.exit()
else :
    k -= b
    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(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-(k-a-b))

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) * (-1))
    else:
        print(a)
else:
    print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = [int(n) for n 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())

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

Submission status: Accepted

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

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())
ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]

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

print(ans)

Submission status: Accepted

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

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

print(a - c)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    a, b, c, k = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

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

    #print("n")


resolve()

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = [int(i) for i in input().split(" ", 4)]
    if k <= a:
        print(k)
        return
    elif k <= a+b:
        print(a)
        return
    else:
        k -= a + b
        print(a - k)


main()

Submission status: Accepted

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

value = 0
if a >= k:
    value = k
    print(value)
else:
    value = a
    if k <= a + b:
        print(value)
    else:
        value += (k-a-b) * (-1)
        print(value)

Submission status: Accepted

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

ans = 0

if(K<=A):
    ans = K

if(K>A and K<=A+B):
    ans = A

if(K>A+B):
    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 + b >= k:
    print(a)
else:
    print(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:
# coding: utf-8
def main():
    a, b, c, k = map(int, input().split())
    if k <= a:
        print(k)
    elif k <= a + b:
        print(a)
    else:
        print(a * 2 + b - k)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
if __name__=="__main__":
    a,b,c,k = map(int, input().split())
    picks = 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 = map(int, input().split())
if A >= K:

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

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

    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)
elif k > a:
    if k-a <= b:
        print(a)
    elif k-a > b:
        print(a-1*(k-a-b))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
A, B, C, K = map(int, input().split())
ans=0
i=0

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

Submission status: Accepted

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

X = K - A
Y = K - A - B
Z = 0

if X >= 0:
    Z += A
    if Y > 0:
        Z -= Y
else:
    Z += K

print(Z)