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: Wrong Answer

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+b>=k:
        print(a)
        sys.exit()
    elif 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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

ans -= K
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
while(K!=0):
    print(A, B, C, K)
    if A!=0:
        if A <= K:
            ans += A*1
            A =0
            K -= A
        else:
            ans += K*1
            A -= K
            K = 0
    elif B!=0:
        if B <= K:
            ans += B*0
            B =0
            K -= B
        else:
            ans += K*0
            B -= K
            K = 0
    elif C!=0:
        if C <= K:
            ans += C*-1
            C =0
            K -= C
        else:
            ans += K*-1
            C -= K
            K = 0

    if A==0 and B==0 and C==0:
        break
print(ans)

Submission status: Wrong Answer

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

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

print(A * 1 + c * (-1))

Submission status: Wrong Answer

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

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

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

ans = _sum + (k * -1)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

a,b,c,k = MAP()
sum = 0

if k > a:
    sum += a
    k -= a+b
    sum -= min(max(0, k), c)
    print(sum)
else:
    print(a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def resolve():
    import sys

    input = lambda: sys.stdin.readline().rstrip()

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

Submission status: Wrong Answer

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

if K >= A:
    a = A
else:
    print(K)
    exit()
if A == 0 and C == 0:
    print(0)
    exit()

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

print(a+c)

Submission status: Wrong Answer

Solution code:
a = [int(i) for i in input().split()]
k = a.pop()
ans = 0
for i in range(3):
    if i==0:
        if k<=a[i]:
            ans = k
            break
        else:
            ans += a[i]
            k -= a[i]
    elif i==1:
        if k<a[i]:
            break
        else:
            k -= a[i]
            continue
    else:
        if k<a[i]:
            ans += (-1)*k
            
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B,C,K=input().split()
A=int(A)
B=int(B)
C=int(C)
K=int(K)
if (0<=A)and(0<=B)and(0<=C)and(1<=K<=A+B+C<=2*10**9):
    if K<=A:
        print(A)
    if A<K<=A+B:
        print(A)
    if A+B<K<=A+B+C:
        a=A-(K-A-B)
        print(a)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


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


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

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



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

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


if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import sys

ABCK = input().split()

A= int(ABCK[0].strip())
B= int(ABCK[1].strip())
C= int(ABCK[2].strip())
K= int(ABCK[3].strip())

N_C = K - (A+B)
if(N_C <=0):
    Sum = A
else:
    Sum = A - N_C
print(Sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
lis=list(map(int,input().split()))
A=lis[0]
B=lis[1]
C=lis[2]
K=lis[3]
ans=0
if(A+B<K):
    c=K-A-B
    ans=A-c
else:
    ans=A
print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:

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

res=0

if k <= a:
    res=k
elif k>a and k<=a+b:
    res=a
else:
    res=a+((k-a+b)*(-1))

print(res)

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
abc = []
for i in range(a):
    abc.append(1)

for j in range(b):
    abc.append(0)

for l in range(c):
    abc.append(-1)

print(sum(abc[0:l]))

Submission status: Wrong Answer

Solution code:
def main():
    A, B, C, D = map(int, input().split())
    ans = 0
    D -= A
    if D <= 0:
        print(A)
        exit()
    D -= B

    if D <= 0:
        print(A)
    else:
        print(A - (D-B))
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = x[0]
b = x[1]
c = x[2]
X = x[3]


if (a+b+c) == 0:
    print(0)
else:
    if (a+b) >= X:
        print(a)
    else:
        extra = X-a-b
        print(a-extra)

Submission status: Wrong Answer

Solution code:
arr = input().split(" ")

a = int(arr[0])
b = int(arr[1])
c = int(arr[2])
d = int(arr[3])

e=a+b

if e >= d:
    print(a)
else:
    print(a-(d-e))

Submission status: Wrong Answer

Solution code:
val = input()
val = val.split(" ")
val = [int(i) for i in val]  # 全部intに変換

ans = 0

if((val[0] >= val[3]) or (val[0]+val[1] >= val[3])):
    ans = 1 * val[0]
    print(ans)
else:
    ans = 1 * val[0] - 1*(val[3]-val[0]-val[1])
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

d = k-a
if d == 0:
  print(a)
elif d < 0:
  print(k)
elif d > 0:
  if b > d:
    print(a)
  else:
    print(d-c)

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

r = 0

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

Submission status: Wrong Answer

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

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

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    a, b, c, k = map(int, input().split())
    ans = 0
    if a >= k:
        print(a)
        return
    k -= a
    if b >= k:
        print(a)
        return
    k -= b
    print(a-k)


if __name__ == '__main__':
    main(sys.stdin.readline, print)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int,input().split())
ans=0
cnt=k
for i in range(3):
    if i==0:
        if a<cnt:
            ans+=a
            cnt-=a
        else:
            ans+=cnt
            cnt=0
    elif i==1:
        if b<cnt:
            cnt-=b
        else:
            cnt=0
    else:
        if cnt>0:
            ans-=c
print(max(ans,0))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = a
k -= a
k -= b
ans -= k

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d=[int(x) for x in input().split()]
count=a
sum=a
if count==d:
    print(a)
else:
    count=count+b
    if count<d:
        if d-count<=c:
          print(sum+((d-count)*-1))
        else:
            print(sum+(c*-1))
    else:
        print(sum)

Submission status: Wrong Answer

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

if (ABCK[0] >= ABCK[3]):
    print(ABCK[3])
elif (ABCK[0] + ABCK[1] >= ABCK[3]):
    print(ABCK[0])
else:
    s = ABCK[2] - (ABCK[3] - ABCK[0] - ABCK[0])
    print(ABCK[0] - s)

Submission status: Wrong Answer

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

AB = A + B

if AB > K:
  print(A)
else:
  print(A + (K - AB) * -1)

Submission status: Wrong Answer

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

s = 0

if a<=k:
  k-=a
  s += a
  print(s)
  exit()
if b<=k:
  k-=b
  print(s)
  exit()
s -= k
print(s)

Submission status: Wrong Answer

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


res = 0

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

Submission status: Wrong Answer

Solution code:
import sys

a,b,c,k=(int(i) for i in input().split())


one = a
zero = k -a 
min = k -a -b

if min < 0:
    min =0

ans = 1*one-1*min
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, c, k = list(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 = a
print(score)

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int,input().split())
print(a)
s=[]
ans=0
for i in range (a):
    s.append(1)
for i in range (b):
    s.append(0)
for i in range (c):
    s.append(-1)
for i in range (k):
    ans+=s[i]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    A, B, C, D = map(int, input().split())
    ans = 0
    D -= A
    if D <= 0:
        print(A)
        exit()
    D -= B

    if D <= 0:
        print(A)
    else:
        print(D - (A+B))
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

# while(k != 0):
#     if a > 0:
#         a -= 1
#         sum += 1
#     elif b > 0:
#         b -= 1
#     elif c > 0:
#         c -= 1
#         sum -= 1
#     k -= 1

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

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(a-k)

Submission status: Wrong Answer

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

ans = 0
end_flag = False

if K > A:
    ans += A

else:
    ans = K
    end_flag = True

if end_flag != False and K - A > B:
    ans += 0

else:
    ans += (K - A) * 0
    end_flag = True

if end_flag != False and K - A - B > C:
    ans += -C

else:
    ans += -(K - A - B)

print(ans)

Submission status: Wrong Answer

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

count = K
ans = 0


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

    if count <= B:
        print(ans)
    else:
        count -= B
        ans -= count
        print(ans)

Submission status: Wrong Answer

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

M=K-(A+B)

if 0>=M:
    print(A)
else:
    print(A-M)

Submission status: Wrong Answer

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


def solve(A: int, B: int, C: int, K: int):
    ans = 0
    if A == 0 and B > 0:
        print(0)
        return
    if K >= A:
        ans += A
    if K >= A + B:
        ans += min(K - (A + B), C) * -1
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def main(a,b,c,k):
    if(a>=k):
        return a
    k2=k-a
    if(b>=k2):
        return a
    k3=k2-b
    return a-k3
    

if __name__=='__main__':
    a,b,c,k=readinput()
    ans=main(a,b,c,k)
    print(ans)

Submission status: Wrong Answer

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

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