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:
a1,a0,am,n = map(int, input().split())

print(min(a1,n) - min(am,max(0,n-a1-a0)))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

# 1 ✕ N
A, B, C, K = list(map(int, input().rstrip().split()))

ans = 0
array = [(A, 1), (B, 0), (C, -1)]

for k, v in array:
    if K > 0:
        n = min(k, K)
        ans += n * v
        K = K - n

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
A,B,C,K = list(map(int, input().split()))
a=1
b=0
c=-1
count =K
point =0
if A< K:
    point +=A
    count -=A
    K -=A
else:
    point +=K
    count =0
    print(point)
    exit()

if B < count:
    point +=0
    count -=B
    K -=B
else:
    point +=0
    count =0
    print(point)
    exit()    

if C <= count:
    point -=C
else:
    point -=count
    count =0
    
print(point)

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

Submission status: Accepted

Solution code:
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

a,b,c,k = NextInts()

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

Submission status: Accepted

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

hoge = max(K - A - B, 0)

print(min(A, K) - hoge)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################
a,b,c,k = map(int,input().split())	
ans = 0
if a>=k:
    ans = 1*k
    print(ans)
    exit()
else:
    ans += 1*a
    #print(ans)
    k = k-a
    #print(k)
    if b >=k:
        print(ans)
        exit()
    else:
        k = k-b
        #print(k)
        
        ans = ans - 1*k 
        print(ans)
        exit()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = list(map(int, input().split()))
a = x[0]
b = x[1]
c = x[2]
k = x[3]
count = 0
ka = k-a
if ka >= 0:
  count += a*1
else:
  count += k*1
if ka > 0:
  kb = ka-b
  kc = kb-c
  if kb > 0:
    count += kb*-1
print(count)

Submission status: Accepted

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

ANS = 0

if A-K <= 0:
    ANS = ANS + A
    num = K - A
    if B - num <= 0:
        Num = num -B
        ANS = ANS - Num 
else:
    ANS = K

print(ANS)

Submission status: Accepted

Solution code:
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
a,b,c,d=get_ints()
if a<d:
    ans1=a 
    d=d-a 
    if b<d:
        ans2=b 
        d=d-b
        if c<d:
            ans3=c 
            d=d-c 
            ans=ans1+ans2-ans3
        else:
            ans=ans1-d
    elif b>=d:
        ans=ans1
elif a>=d:
    ans=d
print(ans)

Submission status: Accepted

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

A = number[0]
B = number[1]
C = number[2]
K = number[3]

n = [A,B,C]
result = 0
j = 1
for i in n:
    if K <= i:
        print(result + K*j)
        break
    else:
        result += j*i
        K = K - i 
        j = j - 1

Submission status: Accepted

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    a,b,c,k=L()
    if k<a:
        print(k)
    elif a+b>=k:
        print(a)
    else:
        tmp=k-(a+b)
        print(a-tmp)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

def maxK(A,B,C,K):
  s=0
  if K<A:
    return K
  else:
    s+=A
    K-=A
  if K<B:
    return s
  else:
    K-=B
  return s-K

print(maxK(A,B,C,K))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = list(map(int, input().split()))
K = N.pop()
l = [0] * 3
for i in range(3):
    l[i] = min(N[i], K)
    K -= l[i]
print(sum(a * b for a, b in zip(l, range(1, -2, -1))))

Submission status: Accepted

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

a,b,c,k=LI()
ans=0

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def print_ans(B):
    for b in B:
        b.sort(key=lambda l: int(l))
        print(" ".join(b))



def main():
    A, B, C, K = read_values()
    
    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().split())

if a>=k:
    print(k)

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

Submission status: Accepted

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

if A >= K:
    print(K)
    exit()
else:
    bc = K - A  # A < K なのでbc >= 1
    assert bc >= 1
    if B >= bc:
        print(A)
        exit()
    else:
        # B < bc
        cc = bc - B
        assert cc >= 1
        print("{:.0f}".format(A - cc))
        exit()

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

s = 0

s += min(a,k)
k -=a
if k<0:
  print(s)
  exit()
k -=b
if k<0:
  print(s)
  exit()
s -= min(c,k)
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

if A <= K:
    a = A
else:
    a = K

if B <= K-a:
    b = B
else:
    b = K-a

c = K - a - b

ans = a - c
print(ans)

Submission status: Accepted

Solution code:
a,b,c,k = [int(i) for i in input().split(' ')]
ret = [a,b,c]
A = 1*a
B = 0
C = -1*c

if a >= k:
    print(1*k)
elif sum(ret[:2]) >= k:
    print(A)
elif sum(ret) > k:
    tmp = k - a - b 
    print(A+(tmp* -1))
else:
    #sum == k
    print(A+B+C)

Submission status: Accepted

Solution code:
a, b, c, k = list(map(int, input().split()))
na = 0
nb = 0
nc = 0
if k < a:
    na = k
else:
    na = a
    k -= a
    if k < b:
        nb = k
    else:
        nb = b
        k -= b
        nc = k
point = na - nc
print('{}'.format(point))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def main():
    A, B, C, K = map(int, input().split())
    l = []

    if K-A<0:
        out = K
        print(out)
        sys.exit()
        
    if K-A>=0:
        l.append(A)
        K = K-A
    if K-B>=0:
        K = K-B
    if K>0:
        m = K * -1
        l.append(m)
    out = sum(l)
    print(out)
main()

Submission status: Accepted

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

tmpk = 0

tmp = 0
flg = True

if a > k:
    print(k)
    flg = False
else:
    tmp = a
    tmpk = k - a
    if tmpk <= 0:
        print(tmp)
        flg = False

if b > tmpk and flg:
    print(tmp)
    flg = False
elif flg:
    tmpk -= b
    if tmpk <= 0:
        print(tmp)
        flg = False

if flg:
    tmp -= tmpk
    print(tmp)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
cnt_a, cnt_b, cnt_c, cnt = map(int, input().split())
if cnt_a >= cnt:
    print(cnt)
elif cnt_a + cnt_b >= cnt:
    print(cnt_a)
else:
    print(cnt_a - (cnt - cnt_a - cnt_b))

Submission status: Accepted

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

Submission status: Accepted

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

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:
a1,b0,cn1,d=map(int,input().split())
Output = 0

if a1 < d:
    Output = a1
    if a1+b0 < d:
      c = d-a1-b0
      Output = Output - c
    elif a1 + b0 >= d:
      pass
elif a1 >= d:
    Output = d
else:
  print("weird")
print(Output)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
'''l=[]
for _ in range(a):
    l.append(1)
for _ in range(b):
    l.append(0)
for _ in range(c):
    l.append(-1)
print(sum(l[:k]))'''
su=0
if a>=k:
    print(k)
else:
    su=su+a
    tem=k-a
    if b>=tem:
        print(su)
    else:
        tem1=tem-b
        print(su-tem1)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read


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

ans = 0

i = min(a, k)
k = max(k-i, 0)
j = min(b, k)
k = max(k-j, 0)
l = min(c, k)

print(i+j*0-l)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
a, b,c,k=map(int,input().split())
if 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= [int(x) for x in input().split()]
if a>=k:
	ans = k
elif a+b>k and a<k:
	ans = a
else: 
	x=k-a-b
	ans = a-x
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


if a >= k:
    print(k)
elif ab >= k:
    print(a)
else:
    print(a - k_ab)

Submission status: Accepted

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

if K>=A:
    K-=A
    sum+=A
elif K<A:
    sum+=K
    K=0

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

if K>=C:
    K-=C
    sum-=C
elif K<C:
    sum-=K
    K=0

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

s = min(a,k)
k -= min(a,k)
k -= min(b,k)
s -= min(c,k)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    ans = 0

    k1 = k - a
    k1 = max(0, k1)
    ans += k - k1
    k = k1

    if k > 0:
        k1 = k - b
        k1 = max(0, k1)
        k = k1

        if k > 0:
            k1 = k - c
            k1 = max(0, k1)
            ans -= k - k1
            k = k1

    print(f'{ans}\n')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

n_a = 0
n_b = 0
n_c = 0

# a
if K > 0:
  
  if K >= A:
    n_a = A
    K = K - A
  else:
    n_a = K
    K = K - A

else:
  n_a = 0


if K > 0:

  if K >= B:
    n_b = B
    K = K - B
  else:
    n_b = K
    K = K - B

else:
  n_b = 0

if K > 0:

  if K >= C:
    n_c = C
    K = K - C
  else:
    n_c = K
    K = K - C

else:
  n_c = 0

ans = (n_a * 1) + (n_b * 0) + (n_c * (-1))
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

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

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

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

Submission status: Accepted

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

if a <= k:
    count += a
else:
    count += k
    print(count)
    exit()
k -= a

if b <= k:
    k -= b
else:
    print(count)
    exit()


count -= k

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

R = K-(A+B)
if R <= 0 :
    R = 0
elif R >= C :
    R = C

S = A - R
if A > K :
    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 and A+B>=K):
  print(A)
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 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())

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if a >= k:
  an = k
  bn = 0
  cn = 0
elif a+b >= k:
  an = a
  bn = k - (a)
  cn = 0
else:
  an = a
  bn = b
  cn = k - (a+b)
  
print(an-cn)

Submission status: Accepted

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

Submission status: Accepted

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

    res += 1 * min(a, k)
    k -= a
    if k > 0:
        k -= b
    if k > 0:
        res += (-1 * min(c, k))
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = [int(x) for x in input().split()]
count1=0
count0=0
count2=0
if a[3]>a[1]:
   count1=a[0]
if a[3]<=a[1]:
    count1=a[3]
if a[3]-a[1]-a[0]>0:
    count2=-(a[3]-a[1]-a[0])
print(count1+count2)

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())
total = 0
for i, n in zip([1, 0, -1], [a, b, c]):
    k -= (p := min(n, k))
    total += i * p
print(total)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

if k < a:
    result = k
elif k <= a + b:
    result = a
else:
    result = 2 * a + b - k

print(result)

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

x = min(a,k)
ans = x
if x < k:
    k -= x
    x = min(b, k)
    if x < k:
        k -= x
        ans -= min(c, k)

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline
def main():
  num_list = list(map(int, input().split()))
  A=num_list[0]
  B=num_list[1]
  C=num_list[2]
  K=num_list[3]
  sum_count=0
  sFlag=True
  i=0
  if(A>=K):
    sum_count=K
    sNum=0
  else:
    sNum=K-A
    sum_count=sum_count+A
  if(B>=sNum):
    sNum=0
  else:
    sNum=sNum-B
  if(sNum!=0):
    sum_count=sum_count-sNum
  else:
    if(C>=sNum):
      sum_count=sum_count-sNum
    else:
      sum_count=sum_count-C
  print(sum_count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
a,b,c,k = map(int, sys.stdin.readline().split())
if a >= k:
    print(k)
else:
    if b >= k - a:
        print(a)
    else:
        c = k-a-b
        print(a-c)

Submission status: Accepted

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

ans = 0
if a >= k: #
  print(k)
  sys.exit()
else:
  ans = a
  k = k -a

if k != 0 and k - b > 0:
  print(a-(k-b))
else:
  print(a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
A,B,C,K=input().split()

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

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

if int(K) > int(A)+int(B):
    ans=int(A)-(int(K)-(int(A)+int(B)))

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

    ans = 0
    diff = a - k
    if diff >= 0:
        print(k)
        return

    diffb = b - (-diff)
    if diffb >= 0:
        print(k-(-diff))
        return
    k = k-(-diff)

    print(k-(-diffb))

solution()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if K > 0 and B > 0:
    if K >= B:
        K -= B
    else:
        K = 0

if K > 0 and C > 0:
    if K >= C:
        K -= C
        ans -= C
    else:
        ans -= K
        K = 0

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

total = 0

if a > 0:
    if a < k:
        total += a
        k -= a
    else:
        total += k
        print(total)
        k = 0

if b > 0 and k > 0:
    if b < k:
        k -= b
    else:
        print(total)
        k = 0

if c > 0 and k > 0:
    if c < k:
        total -= c
        print(total)
    else:
        total -= k
        print(total)

Submission status: Accepted

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

sum_card=0
if A<K:
    sum_card=A
    K-=A
else:
    sum_card=K
    K-=K
if B<K:
    K-=B
else:
    K-=K
sum_card-=K

print(sum_card)

Submission status: Accepted

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

if k<=a:
	amount=k

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

Submission status: Accepted

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

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

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

k -= b
print(a-k)

Submission status: Accepted

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

x = K - A
if x == 0:
    print(A)
elif x < 0:
    print(K)
elif x > 0:
    y = x - B
    if y == 0:
        print(A)
    elif y < 0:
        print(A)
    elif y > 0:
        print(A - y)

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

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

k -= b
if k <= 0:
    print(ans)
    exit()

ans -= k
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
a, b, c, k = [int(i) for i in input().split()]
ans = 0
if a > k:
    ans += k
    print(ans)
    exit()

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

k -= b
if k < 0:
    print(ans)
    exit()

ans += (-1*k)
print(ans)

Submission status: Accepted

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

ret = 0
if a>=k:
    ret += k
else:
    ret += a
    if b >= k-a:
        pass
    else:
        if c >= k-a-b:
            ret += (k-a-b) * -1
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A=list(map(int,input().split()))
ans = 0
if A[0] >= A[3]:
    ans = A[3]
else:
    A[3] = A[3]-A[0]
    ans = A[0]
    A[3] = A[3] -A[1]
    if A[3] > 0:
        ans = ans - A[3]
print(ans)