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:
# -*- coding: utf-8 -*-
a,b,c,k = map(int,input().split())

ans = 0
ans += min(a, k)
k -= a
#print(k, 'a')
if k > 0:
    k -= b
    #print(k, 'b')
if k > 0:
    ans -= min(c, k)
    #print(k, 'c')
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())

a=min(K,A)
b=min(K-a,B)
c=max(K-a-b,0)
ans=a*1+c*(-1)
print(ans)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest


def resolve():
    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)))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 1 1 3"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """2000000000 0 0 2000000000"""
        output = """2000000000"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    A, B, C, K = map(int, input().split())
    answer = 0
    if K >= A:
        answer += A
        K -= A
        if K >= B:
            K -= B
            if K > 0:
                answer -= K
    else:
        answer += K
    print(answer)


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:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    A, B, C, K = lr()
    ans = 0
    if K <= A:
        ans += K
        print(ans)
        return
    ans += A
    K -= A
    if K <= B:
        print(ans)
        return
    K -= B
    ans -= K
    print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    A,B,C,K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

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




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, os

def f():
    args = list(map(int,input().split()))
    if len(args) > 1:
        return args
    return args[0]

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a,b,c,k = f()
    ans = 0
    ac = min(a, k)
    k -= ac
    ans += ac

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

    cc = min(c, k)
    ans -= cc
    print(ans)
solve()

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)
elif 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 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:
a, b, c, k = map(int, input().split())

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

Submission status: Accepted

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

ak = min(a, k)
out1 = ak
k = k-ak
bk = min(b, k)
out2 = 0
k = k-bk
ck = min(c, k)
out3 = -ck

out = out1 + out2 + out3
print(out)

Submission status: Accepted

Solution code:
def solve():
    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:
        k -= b
    else:
        k = 0
    if k > 0:
        ans -= k
    print(ans)


if __name__ == '__main__':
    solve()

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().strip()
a,b,c,k = map(int,input().split())
ans = 0
ans+=min(a,k)
k-=min(a,k)
k-=min(b,k)
ans-=min(c,k)
k-=min(c,k)
print(ans)

Submission status: Accepted

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

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:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

a, b, c, k = Is()
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)
else:
    k -= a

    if k <= b:
        print(a)

    else:
        k -= b

        if k <= c:
            print(a - k)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


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

    return


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())
ans = 0
ans+=min(k,a)
if k>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:
    tmp = k - a - b
    print(a - tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
A = 1
B = 0
C = -1
"""

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
a,b,c,k = map(int, input().split()) 
# b = list(map(int, input().split()))
# n = int(input())
# a = [int(input()) for _ in range(n)]

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

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:
def main():
    A, B, C, K = list(map(int, input().split(' ')))
    print(min([A, K]) - max([0, K - A - B]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


#a=[int(x) for x in input().split()]
#n=int(input())

def main():
    a,b,c,k=[int(x) for x in input().split()]
    ans=0
    
    m=min(a,k)
    ans+=m
    a-=m
    k-=m

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

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

    print(ans)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

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:
# import numpy as np
# import queue
# import heapq


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

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

    print(mv)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

if d > 0:
    if e > 0:
        print(A-min(K-A-B,C))
    else:
        print(A)
else:
    print(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:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

cnt = 0
cntA = min(A, K)

K -= cntA
if K == 0:
    print(cntA)
    exit()

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

if K == 0:
    print(cntA)
    exit()

cntC = min(C, K)
K -= cntC

print(cntA - cntC)
exit()

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
    K -= B
    if K > 0:
        ans -= K
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, K = MAP()

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

Submission status: Accepted

Solution code:
from collections import defaultdict

a,b,c,k=map(int, input().split())
ans=0
if a>=k:
    print(k)
else:
    ans+=a
    k-=a
    if b>=k:
        pass
    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 A < K <= A+B:
    print(A)
else:
    print(A-(K - A - B))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
a, b, c, k = map(int, input().split())
i = min(a, k)
k -= i
k -= min(b, k)
print(i-k)

Submission status: Accepted

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

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
A, B, C, K = map(int, readline().split())


def solve():
    if K <= A:
        return K
    elif K <= A + B:
        return A
    else:
        r = K - A - B
        return A - r


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True

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

    ans += min(A, K)
    K -= A

    if K <= 0:
        print(ans)
        return

    K -= B

    if K <= 0:
        print(ans)
        return

    ans -= K

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    A, B, C, K = map(int, input().split())
    sumL = 0
    if K <= A: 
        sumL += K
        K = 0
    else:
        sumL += A
        K -= A
    if K > B:
        K -= B
    else: K = 0
    if K > 0: sumL -= K
    print(sumL)

    return  0

if __name__ == "__main__":
    solve()

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:
# B - Easy Linear Programming / 

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

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

print(1 * a + b * 0 + c * -1)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
ans = 0
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+B>=K:
    print(A)
else:
    ans=A
    r=K-(A+B)
    ans-=r
    print(ans)

Submission status: Accepted

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

    score = 0

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







if __name__ == "__main__":
    resolve()

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