Problem:


Score : 200 points

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

0 \leq A, B, C

1 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with 1s and one card with a 0.
In this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000



Sample input:
2 1 1 3


Sample output:
2

Submission status: Accepted

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

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたらFalse
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

def main():

    w=1
    j=0
    k=0
    #n=int(input())
    a,b,c,k=map(int, input().split(" "))
    if a>k:
        print(k)
        sys.exit()

    if a+b>=k:
        print(a)
        sys.exit()
    #if a>k:
    #    print(k)
    #    sys.exit()
    print(2*a-k+b)
    #r=int(input())
    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    "1行1つの整数を入力を取得し、整数と取得する"
    #nl=list(map(int, input().split(" ")))#数字の時
    #print(number_list)
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)


    #s=input()
    #a=[int(i) for i in s]#int取るとstrでも行ける
    #print(a)
    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

    ls = ["a", "b", "c", "d", "e"]


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

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

if K <= A:
    point = K
else:
    point = A
    if K - A - B >= 0:
        point = 2*A+B-K

print(point)

Submission status: Accepted

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

print(sum)

Submission status: Accepted

Solution code:

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,c,k=list(map(int,input().split()))
ans=0
if k<=a:
    ans=k
elif k<=a+b:
    ans=a
else:
    z=(k-a-b)*(-1)
    ans=a+z
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-b-a))

Submission status: Accepted

Solution code:
in1 = input()
ins = in1.split()
oneNum = int(ins[0])
zeroNum = int(ins[1])
enoNum = int(ins[2])
num = int(ins[3])


if oneNum >= num:
  print(num)
else:
  sum = oneNum
  num -= oneNum
  num -= zeroNum
  if num <= 0:
    print(sum)
  else:
    sum -= num
    print(sum)

Submission status: Accepted

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

total = 0
if K <= A:
    total = K*1
elif A < K and K <= A+B:
    total = A*1 + (K - A)*0
else:
    total = A*1 + B*0 + (K - A - B)*(-1)

print(total)

Submission status: Accepted

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

for i in range(3):
    if i == 0:
        if k <= a:
            print(k)
            break
        else:
            k -= a

    elif i == 1:
        if k <= b:
            print(a)
            break
        else:
            k -= b

    elif i == 2:
        if k <= c:
            print(a+(-1*k))
        else:
            print(a+c)

Submission status: Accepted

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


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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string,decimal
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,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())

A,B,C,K = II()

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A , B , C , K = map ( int  ,input().strip().split(" ") ) 
l = [ 1 , 0 , -1 ] ;
t = 0 

for ( c,r ) in zip ( l , ( A, B , C ) ) :

	if r >= K :
		t += K * c ;
		break ;
	else :
		K -= r ;
		t += r * c ;
print ( t ) ;

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

Submission status: Accepted

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

while True :
    if k-a <= 0 :
        print(k)
        break
    k -= a
    if k-b <=0 :
        print(a)
        break
    k -= b
    print(a-k)
    break

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = (int(x) for x in input().split())

ans = 0

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

k -= b

if k > 0:
    ans -= k

print(ans)

Submission status: Accepted

Solution code:

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    abck = list(map(int, input().split()))
    count = abck[3]
    r = 0
    
    r += min(abck[0], count)
    count -= min(abck[0], count)
    count -= min(abck[1], count)
    r -= min(abck[2], count)
    count -= min(abck[2], count)

    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if D-A >= 0:
    point = A
    D -= A
    if D-B >= 0:
        D -= B
        if D-C >= 0:
            point -= C
            print(point)
        else:
            point -= D
            print(point)
    else:
        print(point)
else:
    point = D
    print(point)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if k!=0:
	x = min(k, b)
	k = max(k-x, 0)

if k!=0:
	x = min(k, c)
	ans += (-1*x)

print(ans)

Submission status: Accepted

Solution code:


def relu(a, b):
    if(a <= b):
        return 0
    else:
        return a - b

def main():
    args = input().rstrip().split(' ')
    A, B, C, K = int(args[0]),int(args[1]),int(args[2]),int(args[3])
    
    if(A >= K):
        print(K)
    else:
        print(A - relu(K, A+B))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if b>=r:
  print(t)
  exit()
else:
  r-=b

t-=r
print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a,b,c,k=mii()


ans=0

for i,abc in [[a,"a"],[b,"b"],[c,"c"]]:
    if k<i:
        if abc=="a":
            ans+=k
            k=0
        elif abc=="b":
            ans+=0
            k=0
        else:
            ans-=k
            k=0
    else:
        if abc=="a":
            ans+=a
            k-=a
        elif abc=="b":
            ans+=0
            k-=b
        else:
            ans-=c
            k-=c
    if k==0:
        print(ans)
        exit()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


res = 0


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

Submission status: Accepted

Solution code:
# S = input()
# N = int(input())
# A, B = map(int, input().split(' '))
# A = list(map(int, input().split(' ')))

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

if A < K:
  result += A
  K -= A
else:
  result = K
  K -= A

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

if K > 0:
  if C < K:
    result -= C
    K -= C
  else:
    result -= K

print(result)

Submission status: Accepted

Solution code:

def main():
    (A,B,C,K) = list(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))
    else:
        print(A-C)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

card0 = 0
card_1 = 0

if k <= a:
    card1 = k
else:
    card1 = a
    if k-a <= b:
        card0 = k-b 
    else:
        card0 = b
        if k-a-b <= c:
            card_1 = k-a-b
        else:
            card_1 = c

print((card1)*1 + (card0)*0 + (card_1)*(-1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
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:
paramA, paramB, paramC, paramK = list(map(lambda x: int(x), input().split(' ')))

result = min(paramA, paramK)
paramK -= paramA
if paramK > 0:
    paramK -= paramB
    if paramK > 0:
        result -= min(paramC, paramK)

print(result)

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

Submission status: Accepted

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

A = 0
B = 0
C = 0
K = 0

if a >= k:
    A = k
else:
    A = a
    K = k - a
    if b >= K:
        B = K
    else:
        B = b
        K -= b
        C = K
print(A-C)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    a, b, c, k = mi()
    if k <= a + b:
        print(min(a, k))
    else:
        print(a - (k - (a + b)))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
A,B,C,K = LI()
ans = min(A,K)
if A+B<K:
    ans -= K-(A+B)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    if A > K:
        return print(K)

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a, b, c, k = map(int, input().split())
cnt = 0
if k <= a:
    cnt += k
elif (a < k <= a+b):
    cnt += a
elif (a+b < k < a+b+c):
    cnt += a - (k-(a+b))
else:
    cnt += a - c
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]
mp = lambda :map(int,input().split())

a,b,c,k = mp()
if k >= a:
    ans = k - (k-a)
    k -= a
    if k >= b:
        k -= b
        ans -= k
    print(ans)
else:
    print(k)

Submission status: Accepted

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

print(counter)

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = (int(x) for x in input().split())
    ans = 0
    if k <= a:
        ans += k
    elif a + b < k and k > a:
        ans += 2 * a + b - k
    elif a + b >= k and k > a:
        ans += a

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

if K > 0:
    ans -= K

print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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


def solve(a, b, c, k):
    sum = 0
    if k < a:
        return k
    else:
        k = k - a
        sum = a
    if k < b:
        return sum
    else:
        k = k - b
    sum -= k
    return sum

def main():
    a, b, c, k = input_from_console()
    print(solve(a, b, c, k))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Accepted

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

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

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

total = 0

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

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

if K <= C:
    total -= K
else:
    total -= C

print(total)

Submission status: Accepted

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


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

else:
    sum = k

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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