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

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

else:
    ans += a
    temp = k - a
    if (temp <= b):
        pass
    else:
        temp -= b
        ans -= temp

print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    from sys import stdin
    # from collections import defaultdict
    # from collections import deque
    # from collections import Counter
    # import math
    # import random
    input = 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)))

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

Submission status: Accepted

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

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

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

if k>0:
  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
A,B,C,K = map(int,input().split())
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

total = 0

if A>=K:
    total = total + 1*K
    print(total)
else:
    total = total + 1*A
    if K-A==0:
        print(total)
        sys.exit()
    else:
        if (K-A)<=B:
            total = total + 0*(K-A)
            print(total)
            sys.exit()
        else:
            if (K-A-B)<=C:
                total = total + (K-A-B)*(-1)
                print(total)
                sys.exit()
            else:
                total = total + C*(-1)
                print(total)
                sys.exit()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ZZ(): return list(map(int, input().split()))
def Z(): return int(input())

A, B, C, K = ZZ()
ans = 1 * min(A, K)
K -= min(A, K)
ans += 0 * min(B, K)
K -= min(B, K)
ans += -1 * min(C, K)
print(ans)

Submission status: Accepted

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

if k >= a:
    ans += a
    k -= a
else:
    ans += k

k -= b
if k > 0:
    ans += -1*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())
ans = 0
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())
#1 0 -1
t = 0
ans = 0

if a >= k:
    print(k)
else:
    # a < k
    t = k - a

    if b >= t:
        print(a)
    else:
        # b < t
        s = t - b

        print(a-s)

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
    if k==0:
        print(ans);exit()
if k>=b:
    k-=b
    if k==0:
        print(ans);exit()
print(ans-k)

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 = [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())
if a>=k:
  print(k)
else:
  if 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:
    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())
m=0
m+=min(A,K)

if K-A-B>0:
  m-=K-A-B
  
print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    a,b,c,k = map(int, input().split())
    ans = 0
    if k > 0:
        ans += min(a,k)*1
        k -= min(a,k)
    if k > 0:
        k -= min(b,k)
    if k > 0:
        ans += min(c,k)*(-1)
        k -= min(c,k)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = lambda: sys.stdin.readline()


def cin_int_list():
    return [int(x) for x in input().split()]


def cin_int_iter():
    return (int(x) for x in input().split())


def cin_int():
    return int(input())


def cout_int_iter(a):
    print(' '.join(map(str, a)))


def iota(n, start=0):
    return list(range(start, n))


def cin_digits_list():
    return [ord(x) - ord('0') for x in input()]


def main():
    a, b, c, k = cin_int_iter()

    ret = 0

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

    if k == 0:
        print(ret)
        return

    k -= min(b, k)

    if k == 0:
        print(ret)
        return

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

    print(ret)


main()

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

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

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

if k<=a+b:
    print(a)
    exit()
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:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B, C, K = lr()
answer = min(A, K)
K -= min(A, K)
if K > 0:
    K -= min(B, K)
    if K > 0:
        answer -= min(C, K)
print(answer)

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


def main():
    A, B, C, K = map(int, input().split())
    if K <= A:
        print(K*1)
        exit()
    if K <= A+B:
        print(A)
        exit()
    if K <= A+B+C:
        print(A-(K-A-B)*1)
        exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
nums=input().split()
A=int(nums[0])
B=int(nums[1])
C=int(nums[2])
K=int(nums[3])
if K<=A:
    maxsum=K
elif K<=A+B:
    maxsum=A
else:
    maxsum=A-(K-A-B)
print(maxsum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    A, B, C, K = map(int, input().split())

    if A >= K:
        print(K)
        return
    ans = A
    K -= (A + B)
    if K > 0:
        ans -= K
    print(ans)


main()

Submission status: Accepted

Solution code:


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

sum = 0
count = 0
if a >= k:
    print(k)
else:
    if 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 A <= K:
    ans += A
    K -= A
else:
    ans += K
    print(ans)
    quit()

if B <= K:
    K -= B
else:
    ans += K * 0
    print(ans)
    quit()
print(ans - K)

Submission status: Accepted

Solution code:
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 numpy as np
if __name__ == "__main__":
    A, B, C, K = map(int, input().split())
    ans = 0
    loop = min(A, K)
    K = K - loop
    ans += loop
    loop = min(B, K)
    K = K - loop
    # +-0
    loop = min(C, K)
    K = K - loop
    ans -= loop
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
numA = min(a, k)
numB = min(b, k-numA)
numC = min(c, k-numA-numB)
print(numA - numC)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,c,k = mi()

ima = k

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

ima = k - a

if b >= ima:
    print(a)
    exit()

ima = ima - b

nokori = min(c,ima)
print(a-nokori)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
s = min(a, k)
k = k - s
t = min(b, k)
k = k - t
u = min(c, k)
print(s-u)

Submission status: Accepted

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

# process
ans = 0
if A+B>=K:
    if A > K:
        ans = K
    else:
        ans = A
else:
    ans = A-(K-A-B)

# output
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
    if K <= A:
        print(K)
    elif K <= A + B:
        print(A)
    else:
        print(A-(K-A-B))      
    
main()

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:
        k -= b
        if c >= k:
            ans -= k
print(ans)

Submission status: Accepted

Solution code:
def main():
    a,b,c,k = map(int,input().split())
    plus_one = min(a,k)
    k -= plus_one
    zero = min(b,k)
    k -= zero
    minus_one = min(c,k)
    print(plus_one * 1 + zero * 0 + minus_one * (-1))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(a: int, b: int, _c: int, k: int) -> int:
    if k <= a + b:
        return min(k, a)
    return a - (k - a - b)


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    A, B, C, K = map(int, input().split())
    result = solve(A, B, C, K)
    print(result)


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)

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
ans += -1 * k
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(main())

Submission status: Accepted

Solution code:
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def main():
    a,b,c,k = ints()
    if k<=a:
        print(k)
    elif k<=a+b:
        print(a)
    elif k<=a+b+c:
        print(2*a+b-k)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

ans = 0

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

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

Submission status: Accepted

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

kotae = 0

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

print(kotae)

Submission status: Accepted

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

remaining = K
ans = 0
if A <= remaining:
    ans += A
    remaining -= A
else:
    ans += remaining
    remaining = 0

if B <= remaining:
    remaining -= B
else:
    remaining = 0

ans -= remaining

print(ans)

Submission status: Accepted

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

x=k-a-b
y=a-x
if k<a:
    print(k)
elif x<=0:
    print(a)
else:
    print(y)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
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()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

A, B, C, K = mi()

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

Submission status: Accepted

Solution code:
a, b, c, k = [int(i) for i in input().split()]
if a + b <= k:
    print(a - (k - a - b))
else:
    print(min(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:
    cal = K - (A+B)
    print(A + cal*(-1))

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())  # x = 1, y = 2

sum_card = 0
sum_n = 0

if k <= a:
    print(k)
    exit()
elif k <= (a + b):
    print(a)
    exit()
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
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
s += min(A, K)
K -= A

if K > 0:
    K -= B

if K > 0:
    s -= min(C, K)

print(s)

Submission status: Accepted

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

ans=min(k,a)
k=k-ans 
ans1=min(k,b)
k=k-ans1
ans3=min(k,c)
k=k-ans3
print(ans-ans3)

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:
def main():
    from builtins import int, map, list, print, min
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A, B, C, K = list(map(int, input().strip().split()))
ans = 0
tmp = min(A, K)
ans += tmp
K -= tmp
if K <= 0:
  pass
else:
  tmp = min(B, K)
  K -= tmp
  if K <= 0:
    pass
  else:
    tmp = min(C, K)
    ans -= tmp
print(ans)

Submission status: Accepted

Solution code:
numbers=input().split(" ")
A=int(numbers[0])
B=int(numbers[1])
C=int(numbers[2])
K=int(numbers[3])
if K<=A:
    print(K)
elif K<=B+A:
    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 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()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K=list(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:
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))

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

result = 0

m = [1, 0, -1]
options = [a, b, c]

idx = 0
while k > 0:
    get = min(k, options[idx])
    result += get*m[idx]

    idx += 1
    k -= get
print(result)

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

Submission status: Accepted

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

s = 0
s += min(a, d)
if min(a, d) == d:
  print(s)
elif min(a+b, d) == d:
  print(a)
else:
  d -= a + b
  print(a-min(c, d))

Submission status: Accepted

Solution code:

def main():
  a, b, _, k = map(int, input().split())

  ans = 0

  v = min(a, k)
  ans += v
  k -= v

  if k < 0:
    print(ans)
    return

  k -= min(b, k)

  if k < 0:
    print(ans)
    return

  ans -= k

  print(ans)


main()

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    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))


if __name__ == "__main__":
    setrecursionlimit(10000)
    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

Line = [int(s) for s in input().split()]

A,B,C,K = Line[0],Line[1],Line[2],Line[3]

ans = 0

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

if B >= K:
    print(ans)
    sys.exit()
else :
    K -= B
    print(ans - K)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import *

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

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

cnt=0

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

if k>0:
	k-=b
	if k>0:
		cnt-=k
		
print(cnt)