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

a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
    sys.exit()

total = a
k = k - a
if k <= 0:
    print(total)
    sys.exit()

k = k - b
if k <= 0:
    print(total)
    sys.exit()

print(total - k)

Submission status: Accepted

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

Submission status: Accepted

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

if k>=c:
    k=k-c
    s=s+c*(-1)
else:
    
    s=s+k*(-1)
    print(s)
    sys.exit()
    
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if D > A:
 
    ancer = 1 * A + 0 * (D - A) + (-1 *(D - A - B))
    
else:
    ancer = 1 * D

print(ancer)

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

print(ans)

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

Submission status: Accepted

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
A, B, C, K = map(int, stdin.readline().rstrip().split())
#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,k=LI()
  ans=0
  if k<a:
    ans=k
  elif k<a+b:
    ans=k
  else:
    ans=a
    ans-=(k-(a+b))
  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
num_list = [int(i) for i in input().split()]

if num_list[3] <= num_list[0]:
    print(1*num_list[3])
elif num_list[3] > num_list[0] and num_list[3] <= num_list[0] + num_list[1]:
    print(1*num_list[0])
else:
    print(1*num_list[0]+(-1*(num_list[3] - (num_list[0]+num_list[1]))))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
x = 0

if K - A >= 0:
    x = K - A
    count = A * 1
else:
    count = K * 1

if x >= 0:
    x = x - B
    if x >= 0 and C != 0:
        C = K - A - B
        count = count + C * -1

print(count)

Submission status: Accepted

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

if a >= k:
  a = k
  b = 0
  c = 0
if a < k and a+b >= k:
  c = 0
if a+b < k:
  c = k - a - b
  
sum_a = 1 * a
sum_c = -1 * c
  
print(sum_a + sum_c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
Ts = 0
sA = K - A
if sA > 0:
    sB = sA - B
    if sB > 0:
        sC = sB - C
        if sC < 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
        elif sC == 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
    elif sB == 0:
        Ts = ((K - sA) * 1) + (sB * 0)
    else:
        Ts = ((K - sA) * 1) + ((sA - sB) * 0)
elif sA == 0:
    Ts = A * 1
else:
    Ts = K * 1
print(Ts)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

sum =0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys


def test():
    A, B, C, K = map(int, input().split())
    ans = 0
    if A > 0 and (K - A) > 0:
        ans += A
        K -= A
    elif A > 0 and (K - A) <= 0:
        ans += K
        print(ans)
        sys.exit()

    if B > 0 and (K - B) > 0:
        K -= B
    elif B > 0 and (K - B) <= 0:
        print(ans)
        sys.exit()

    ans -= K
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Accepted

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

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

Submission status: Accepted

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

n_a = 0
n_b = 0
n_c = 0

if K > A:
  n_a = A

  if K-A > B:
    n_b = B
    n_c = K-A-B
  
  if K-A == B:
    n_b = B
    n_c = 0
  
  if K-A < B:
    n_b = K-A
    n_c = 0 

if K == A:
  n_a = K
if K < A:
  n_a = K

print(n_a+(-1)*n_c)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

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

Submission status: Accepted

Solution code:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
#      .      '                    Udit Gupta @luctivud         ,              
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            ##     ##  #######  # #  ######
                            ##     ##  ##   ##  ###    ##
                            ##     ##  ##    #  # #    ##
                            #########  #######  # #    ##
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import sys
import math as mt
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))

def printwsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end="tst, ")

MOD = int(1e9+7); BABYMOD = 998244353;
# ################################ HELPER PROGRAMS USED ###################################
# ################################## MAIN STARTS HERE #####################################
# for _testcases_ in range(int(input())):
a, b, c, k = get_ints()
ans = 0
ans += min(a, k)
k = k - ans
k = max(0, k-b)
ans -= min(k, c)
print(ans)

# #########################################################################################
'''
THE LOGIC AND APPROACH IS BY ME @luctivud.
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
: DO NOT PLAGIARISE.
'''

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()) #a1 a2 a3

if k <= a:
  print(k)
else:
  k1=k-a
  if k1 <=b:
    print(a)
  else:
    k2=k1-b
    print(a-k2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
if K > A:
    AK = K - A
    AKB = abs(AK - B)
    print(A - AKB)
else:
    print(K)

Submission status: Accepted

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

k2 = k1-b
if k2<=0:
    print(ans)
    sys.exit()
else:
    ans=ans

print(ans-k2)

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
dif = K - (A + B)
ans = 1 * A

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

Submission status: Accepted

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

k -= A
if k < 0:
    k = 0
    result += 1 * K
else:
    result += 1 * ( A )

    k -= B
    if k > 0:

        result -= 1 * ( k )

print(result)

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

# a = 1 の枚数
# b = 0 の枚数
# c = -1 の枚数
# k 引ける枚数

if a < 0:
    a = 0

if b < 0:
    b = 0

if c < 0:
    c = 0

max_val = 0

x = k - a
# 残り枚数が0以上の場合aはすべて引ける
if x >= 0:
    max_val = max_val + a * 1
    k = x
elif x < 0:
    max_val = max_val + k * 1
    k = 0


if k > 0:
    x = k - b
    if x >= 0:
        max_val = max_val + b * 0
        k = x
    elif x < 0:
        k = 0
        max_val = max_val + k * 0


if k > 0:
    x = k - c
    if x >= 0:
        max_val = max_val + c * -1
    elif x < 0:
        max_val = max_val + k * -1

print(max_val)

Submission status: Accepted

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

A = 0
if (a<d):
  if (0 < (d-a-b)):
    A = a-(d-a-b)
  else:
  	A = a
else:
  A = d
print(A)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    a, b, c, k = LI()
    if k < a:
        print(k)
    else:
        k -= a
        if k < b:
            print(a)
        else:
            k -= b
            print(a- k)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
P = 0
S = 0
while S==0:
    P += A
    K -= A
    if K < 0:
        P -= abs(K)
        break
    elif K == 0:
        break

    K -= B
    if K <= 0:
        break

    P -= C
    K -= C
    if K <= 0:
        P += abs(K)
        break
    S=1
print(P)

Submission status: Accepted

Solution code:
abck=list(map(int,input().split()))
a=abck[0]
b=abck[1]
c=abck[2]
k=abck[3]

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

Submission status: Accepted

Solution code:

if __name__ == "__main__":
    A, B, C, K = map(int, input().split())
    cnt = 0
    if K >= A:
        cnt += A * 1
        K -= A
        if K >= B:
            K -= B
            if K >= C:
                cnt += C * -1 
            else:
                cnt += K * -1
        else:
            K -= K
    else:
        cnt += K * 1
        K -= K        
    print(cnt)

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
count = 0
# for i in range(A):
#     ans += 1
#     if i 

# while count != K:
#     if count <= A:
#         ans +=1
#         count+=1
#     elif count <= B:
#         count+=1
#     else:
#         ans -= 1
#         count+=1

if A+B>=K:
    if A >= K:
        ans += K
    else:
        ans += A
else:
    ans += A
    
    count = K-(A+B) # 残り枚数
    ans-=count
        
    
print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = [int(n) for n in input().split()]
c = 0
k = K
c += min(A, K)
K -= min(A, K)
if K==0:
    print(c)
else:
    K -= B
    if K==0:
        print(c)
    else:
        c -= K
        print(c)

Submission status: Accepted

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


def function(a,b,c,k):
    count =0
    if a>=k:
        return k
    else:
        count =a
        k =k-a
        a=0
        if b>=k:
            return count
        else:
            k-=b
            b=0
            count-=k

        return count
print(function(a,b,c,k))

Submission status: Accepted

Solution code:
a, b, c, counts = map(int, input().split())
x = a - counts
if x >= 0:
    print(1 * counts)
else:
    if x < 0:
        y = b + x
        if y < 0:
            z = c + y
    print(1 * a + -1 * (-(b + x)))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
from bisect import bisect_left, bisect_right, insort
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def MS(): return map(str,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
#N = I()
#A = [LI() for _ in range(N)]

a, b, c, k = MI()

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

Submission status: Accepted

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]

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

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

if b < k:
    k -= b
    score -= k

print(score)

Submission status: Accepted

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

if K <= A :
   ans = K
   print(ans)

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

   elif M >= B :
      L = M - B
      ans = A - L
      print(ans)

Submission status: Accepted

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

for i in range(1,4):
    if i == 1:
#AとKを比較して得点を加算する
#KとAを比較してAよりもKが多ければそのまま加算する
        if A <= K:
            ans += A
            K -= A
        #KとAを比較してAよりもKが少なければK個分加算する
        else:
            ans += K
            break
        #print(K)
        
    elif i == 2:
        #BとKを比較してKを減らす
        #BとKを比較してBよりもKが多ければそのまま減算する
        if B <= K:
            K -= B
        #BとKを比較してBよりもKが少なればKをゼロにして処理を終了する
        else:
            K = 0
            break
        #print(K)

    elif i == 3:
        #CとKを比較して得点を減算する
        #KとCを比較してCよりもKが多ければそのまま加算する
        if C <= K:
            ans -= C
        #KとCを比較してCよりもKが少なければK個分加算する
        else:
            ans -= K
        #print(K)

#答えを表示する
print(ans)

Submission status: Accepted

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


ka = k - a

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().strip().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()))

cardList = [A,B,C]
numList = [0,0,0]
Hand = K
count = 0

def check(card):
  global Hand
  if Hand - card <= 0:
    return Hand
  else:
    return card

for card in cardList:
  numList[count] = (check(card))
  Hand = Hand - card
  count += 1
  if Hand <= 0:
    break;

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

Submission status: Accepted

Solution code:
# coding: utf-8
a, b, c, k = map(int, input().split())
x = 0
y = k

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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())
res=0

if not a==0:
    if a<k:
        res+=a
        k-=a
    elif a==k:
        print(a)
        exit()
    else:
        print(k)
        exit()
if not b==0:
    if b<k:
        k-=b
    elif b==k:
        print(res)
        exit()
    else:
        print(res)
        exit()
if not c==0:
    if c<k:
        print(res-c)
        exit()
    elif c==0:
        print(res-c)
        exit()
    else:
        print(res-k)
        exit()
else:
    print(res)
    exit()

Submission status: Accepted

Solution code:
m = list(map(int, input().split()))
count = 0
k = m[3]
if m[0] < k:
    count = m[0]
    k = k - m[0]
    if m[1] < k:
        k = k - m[1]
        if m[2] < k:
            count -= m[2]
        else:
            count -= k
    else:
        count
else:
    count = k
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

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

if A < K:
    ans += A
    K -= A
else:
    ans += K
    K -= K
    
if (K != 0) and (B < K):
    K -= B
else:
    K -= K

if (K != 0) and (C < K):
    K -= C
    K -= C
else:
    ans -= K
    K -= K

print(ans)

Submission status: Accepted

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

score = 0

if K < A:
    score = K

else:
    score = A
    K = K - A
    if K > 0 and K < B:
        score = score
    elif K > 0 and K >= B:
        score = score
        K = K - B
        
        if K > 0:
            score = score - K

print(score)

Submission status: Accepted

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

# for i in range(K):
# 	if A > 0:
# 		sum += 1
# 		A -= 1
# 	elif B > 0:
# 		B -= 1
# 	else:
# 		sum -= 1
# 		C -= 1

# print(sum)

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

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().split())
#print(A,B,C,K)
#a a <A
#b b <B
#c K-a-b <C 
if K < A:
    ans=K
elif K-A <= B and K>=A:
    ans=A
else :
    ans=A-(K-A-B)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#2
a,b,c,k = input().split(' ')
out = 0
a = int(a)
b = a + int(b)
c = b + int(c)
k = int(k)

if k <= a:
    out = k
elif k <= b:
    out = a
elif k <= c:
    out = a - (k - b)

print(out)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count, score = 0, 0

c = min(A, (K - count))
score += 1 * c
count += c
if count < K:
    c = min(B, (K - count))
    score += 0 * c
    count += c

    if count < K:
        c = min(C, (K - count))
        score += -1 * c
        count += c

print(score)

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

Submission status: Accepted

Solution code:
def main():
	a,b,c,k = [int(x) for x in input().split(" ")]

	m = min(a, k)
	s = m
	if m <= k:
		k -= m
		m = min(b, k)
		if m <= k:
			k -= m
			m = min(c, k)
			s -= m

	print(s)

main()

Submission status: Accepted

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

    if a>k:
        print(k)
    elif a + b >= k:
        print(a)
    elif a+b<k:
        d=k-a-b
        print(a-d)
resolve()

Submission status: Accepted

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

if K <= A:
    ans = K
elif A+B >= K:
    ans = A
else:
    ans = 2*A+B-K

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))

t = inpl()
a = t[0]
b = t[1]
c = t[2]
k = t[3]
cnt = 0

if k == a + b + c:
    cnt = a - c

if k >= a + b and k < a + b + c:
    cnt = a - (k - (a + b))

if k >= a and k < a + b:
    cnt = a

if k < a:
    cnt = k

print(cnt)

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

Submission status: Accepted

Solution code:
a=input().split()
pl1=int(a[0])
pl0=int(a[1])
pl_1=int(a[2])
draw=int(a[3])
#print(pl1,pl0,pl_1,draw)
if(pl1>=draw):
  print(draw)
elif(pl1+pl0>=draw):
  print(pl1)
else:
  #all_card=pl1+pl0+pl_1
  #print(all_card)
  draw_pl_1=draw-pl1-pl0
  #print(draw_pl_1)
  print(pl1-draw_pl_1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
(A, B, C, K) = list(map(int, input().split()))
items = [
    (A, 1),
    (B, 0),
    (C, -1)
]

_sum = 0
k = K
for num_cards, val in items:
    if num_cards <= k:
        num = num_cards
        k -= num_cards
    else:
        num = k
        k = 0
    _sum += (val * num)
    if k == 0:
        break

print(_sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input_line = input().split()
a = int(input_line[0])
b = int(input_line[1])
c = int(input_line[2])
k = int(input_line[3])

def return_answer(a,b,c,k):
    answer = 0
    if a < k:
        answer += a
        count = k - a

        if b < k:
            count -= b
            answer -= count

    elif a >= k:
        answer = k

    return answer

print(return_answer(a,b,c,k))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def q2():
    A, B, C, K = (int(i) for i in input().split())
    ans = 0

    if K <= A:
        ans += K
        return ans
    else:
        K -= A
        ans += A

    #print(K, ans)
    if K <= B:
        return ans
    else:
        K -= B

    #print(K, ans)
    if K <= C:
        ans -= K
        return ans
    else:
        ans -= C
        return ans


if __name__ == '__main__':
    print(q2())