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:
#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil, factorial, log,tan,pi,cos,sin,radians
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
from fractions import Fraction
from functools import reduce
import string
import sys
import os
import re
inf = float('inf')
mod_ = int(1e9) + 7
mod = 998244353

def factors(n):
    from functools import reduce
    return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sieve(m):
    n=1
    primes = {}
    arr=set([])
    for i in range(2, int(m ** 0.5) + 1):
        a = n // i
        b = m // i
        for k in range(max(2, a), b + 1):
            c = i * k
            primes[c] = 1

    for i in range(max(n, 2), m + 1):
        if i not in primes:
            arr.add(i)

    return arr


class DisjointSetUnion:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
 
    def find(self, a):
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a:
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a
 
    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a != b:
            if self.size[a] < self.size[b]:
                a, b = b, a
 
            self.num_sets -= 1
            self.parent[b] = a
            self.size[a] += self.size[b]
 
    def set_size(self, a):
        return self.size[self.find(a)]
 
    def __len__(self):
        return self.num_sets

def isprime(t):
    for i in range(2,int(t**0.5)+1):
        if t%i==0:
            return False
    return True
def semiprime(x):
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            if isprime(i) and isprime(x//i) and i!=x//i:
                return True
    return False



def main():

    a,b,c,k=map(int,input().split())
    ans=0
    ans+=min(k,a)
    k-=min(k,a)
    a-=min(k,a)
    # print(k,ans)
    ans+=0*min(k,b)
    k-=min(k,b)
    b-=min(k,b)
    ans-=min(k,c)
    k-=min(k,c)
    # a-=min(k,a)
    print(ans)
        

        
    




    



# region fastio

BUFSIZE = 8192

class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

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


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

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

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A,B,C,K=input().split(" ")
A=int(A);B=int(B);C=int(C);K=int(K)
SUM=0
if A <= K :#AはK以下であれば
    SUM= 1 * A
    K=K-A
    if B <= K:
        K=K-B
        SUM=SUM + -1*K
        print(SUM)
    else:
        print(SUM)
else:
    print(1*K)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().rstrip().split())
k1 = min(a, k)
k0 = min(b, k - k1)
km = min(c, k - k1 - k0)

r = k1 - km
print(r)

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

sum = 0

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

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


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

print(sum)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

total = min(a, k) * 1
k = max(k - a - b, 0)

total += min(c, k) * (-1)

print(total)

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)
    else:
        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:
A, B, C, K = input().split()
A, B, C, K = int(A), int(B), int(C), int(K)

if K >= A:
    Anum = A
    N = K - A
else:
    Anum = K
    N = 0

if N >= B:
    Bnum = B
    N = N - B
else:
    Bnum = N
    N = 0

Cnum = N

Total = Anum * 1 + Bnum * 0 + Cnum * (-1)

print(Total)

Submission status: Accepted

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

tot += min(a, k)
mini = min(a,k)
a -= mini
k -= mini
#print(a, k, tot)
if(k > 0):
    mini = min(b,k)
    b -= mini
    k -= mini
if(k > 0):
    tot -= min(c,k)

print(tot)

Submission status: Accepted

Solution code:
a, b, c, k = [int(i) for i in input().split()]
if a >= k:
    print(k)
else:
    count = a
    k -= a
    if b >= k:
        print(count)
    else:
        k -= b
        print(count - k)

Submission status: Accepted

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

if(a >= k):
    print(k, end="")
else:
    k2 = k - a
    if(b >= k2):
        print(a, end="")
    else:
        k2 -= b
        print(a-k2, end="")

Submission status: Accepted

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

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

    if A >= K:
        print(K)
        return

    total = A
    K -= A

    if B >= K:
        print(total)
        return

    K -= B

    total += -K

    print(total)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def one_int():
    return int(input())

def one_str():
    return input()

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

A,B,C,K = input_int()

sums=0
if A<K:
    K-=A
    sums = A
    if B<K:
        K-=B
        if C<K:
            sums -= C
        else:
            sums -= K
    else:
        pass

else:
    sums += K


print(sums)

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:
    k-=b
else:
    k = 0

if c<k:
    ans-=c
    k-=c
else:
    ans-=k
    k = 0

print(ans)

Submission status: Accepted

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

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

k = k -b

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

Submission status: Accepted

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

score = 0


if K <= A+B:
    score = min(A,K)
else:
    score = A - min(C, (K - (A+B)))


print(score)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ka = k - a
kb = ka - b

if ka > 0:
    if kb > 0:
        ans = a
        ans += kb * -1
    else:
        ans = a
else:
    ans = k * 1

print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = (int(i) for i in input().split())  
tmp_cnt = k
tmp_sum = 0
if a <= k:
  tmp_sum = a
else:
  tmp_sum += k
tmp_cnt -= a
tmp_cnt -= b
if tmp_cnt>0:
  tmp_sum += tmp_cnt*(-1)
print(tmp_sum)

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

Submission status: Accepted

Solution code:
x = input().split()
A = int(x[0])
B = int(x[1])
C = int(x[2])
K = int(x[3])
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())
#sum=a*1+b*0-c*1
if a>=k:
    print(1*k)
if a<k and a+b>=k:
    print(1*(k-b))
if a<k and a+b<k and a+b+c>=k:
    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 = list(map(int, input().split()))

max = 0
if(a >= k):
  max = k
else:
  max = a
  k -= a
  if(b >= k):
    pass
  else:
    k -= b
    max -= k

print(max)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
one, zero, minus_one, choice = map(int, input().split())
tmpsum = 0

if one >= choice:
    print(choice)
else:
    tmpsum = one
    choice = choice - one

    if zero >= choice:
        print(tmpsum)
    else:
        choice = choice - zero
        print(tmpsum - choice)

Submission status: Accepted

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

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

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

if k>c:
    ans = ans -c
elif 0<k:
    ans = ans -k

print(ans)

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

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

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

def max_check():
    if (A >= K):
        return(K)
    elif(A+B >= K):
        return(A)
    else:
        return(A - (K-A-B))

print(max_check())

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=input("")
l_str=N.split()
l=[int(s) for s in l_str]

#l[0]が1,l[1]が0,l[2]が-1,l[3]がkの枚数
max;


if l[0]>=l[3]:
    max=1*l[3]
elif l[0]+l[1]>=l[3]:
    max=1*l[0]
else:
    max=1*l[0]-1*(l[3]-(l[0]+l[1]))

print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def ISI(): return map(int, sys.stdin.readline().rstrip().split())

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

Submission status: Accepted

Solution code:
def main():
    A, B, _, K = map(int, input().split())
    if A > K:
        print(K)
        quit()
    print(A - max([0, 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())

a = min(K, A)  # 1を選ぶ数
G = K - a
b = min(G,B)#０を選ぶ数
F = G - b
c = min(F,C)
D = F - c
print(a+(-1*c))

Submission status: Accepted

Solution code:
one,zero,ng_one,card = map(int, input().split())

if card < one:
    print(card)
elif card <= one+zero:
    print(one)
else:
    print(one - (card - one - zero))

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

Submission status: Accepted

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

max = 0

if(K >= A):
    max += A
    K -= A
else:
    max += K

K -= B

if(K > 0):
    max -= K

print(max)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max)

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

    if k <= a:
        print(k)
        return

    if k <= b + a:
        print(a)
        return

    print(a-(k - a-b))
resolve()

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

Submission status: Accepted

Solution code:
import sys
readmi = lambda: map(int, sys.stdin.readline().split())

A, B, C, K = readmi()
# result var
max_sum = 0

# check 1
max_sum = min(A, K)
K = K - max_sum

# check 0
if K > 0:
  K = K - min(B, K)

# check - 1
if K > 0:
  max_sum = max_sum - min(K, C)
# print result
print(max_sum)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    import sys
    
    a, b, c, k = tuple(map(int, sys.stdin.readline().split()))
    
    total = 0
    if(k>a):
        total += 1*a
        k -= a
        if(k>b):
            k -= b
            if(k>c):
                total += -1*c
            else:
                total += -1*k
    else:
        total = 1*k
    print(total)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

if b > k:
    ans += 0*k
    k = 0
else:
    ans += 0*b
    k -= b

if c > k:
    ans += -1*k
    k = 0
else:
    ans += -1*c
    k -= c


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
l = [int(i) for i in input().split()]
num = [1,0,-1]
c = 0
s = 0
k = l[-1]
for i in range(3):
    
    if c + l[i] > k:
        s += num[i] *(k-c)
        break
    else:
        s += l[i] * num[i]
        c+=l[i]
   
print(s)

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

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

Submission status: Accepted

Solution code:
nums = [int(e) for e in input().split()]

if nums[0]<nums[3]:
    max=nums[0]
    if nums[0]+nums[1]<nums[3]:
        max -= (nums[3]- (nums[0]+nums[1]))
else:
    max=nums[3]

print(max)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve(string):
    a, b, c, k = map(int, string.split())
    if k <= a:
        return str(k)
    if k <= a + b:
        return str(a)
    return str(a - (k - a - b))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = min(A,K)
K = K-A-B
if K <= 0:
  print(ans)
  exit(0)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-
def max_sum(A, B, C, K):
    if K < A: return K
    elif K < A+B :  return A
    else: return A - (K-(A+B))

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

count = K
score = 0

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

ans = 0

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

K = K - A - B

if (K > 0):
  ans = ans - K

print (ans)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

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

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:
import math
def main():
    A, B, C, K = map(int, input().split())

    point = 0
    if A+B >= K:
        point = min(A,K)
    else:
        point = A - (K-(A+B))

    print(point)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
if __name__ == "__main__":
	a, b, c, k = map(int, input().strip().split(' '))
	s, i = 0, 0
	if k <= a:
		s = k
	elif k > a:
		s = a
		k -= a
		if k > b:
			k -= b
			s -= k
	print(s)

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

total = 0
plus_num = 0
per_num = 0
minus_num = 0

if a < k:
  plus_num = a
  k -= a
else:
  plus_num = k
  k = 0

if b < k:
  per_num = b
  k -= b
else:
  per_num = k
  k = 0

if c < k:
  minus_num = c
  k -= c
else:
  minus_num = k
  k = 0

# print(plus_num, per_num, minus_num)

total = plus_num - minus_num
    
print(total)

Submission status: Accepted

Solution code:
a, b, c, k=map(int, input().split())
l=[a,b,c]
v=[1,0,-1]
ans=0
for i in range(3):
    ans+=min(l[i], k)*v[i]
    k-=min(k,l[i])
    if k==0: break
print(ans)

Submission status: Accepted

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

k = K
a = 0
b = 0
c = 0

if A <= k:
  a = A
  k -= a
else:
  a = k
  k = 0

if B <= k:
  b = B
  k -= b
else:
  b = k
  k = 0

if C <= k:
  c = C
  k -= C
else:
  c = k
  k = 0

print(a-c)

Submission status: Accepted

Solution code:
import sys
a, b, c, k = map(int,sys.stdin.readline().rstrip().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 (a+b)>=k:
    print(a)
else:
    minus = k-(a+b)
    print(a-minus)

Submission status: Accepted

Solution code:
import sys
A, B, C, K = map(int, input().split())
c = 0
if K <= A:
    c += K
    print(c)
    sys.exit()
else:
    c += A
    K -= A
if K <= B:
    print(c)
    sys.exit()
else:
    K -= B
    c -= K
    print(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(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:
    max_num = a - (k - a - b)
    print(max_num)

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

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

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

ans += k*(-1)

print(ans)

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:
s = input().split() 
if len(s) == 4:
    a = int(s[0]) # 1
    b = int(s[1]) # 0
    c = int(s[2]) # -1
    k = int(s[3]) # 枚数

    a_len = a if k > a else k
    b_len = b if (k-a_len) > b else (k-a_len)
    c_len = c if (k-a_len-b_len) > c else (k-a_len-b_len)

    max = 1 * a_len + 0 * b_len + (-1) * c_len

    print(max)

Submission status: Accepted

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