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:
A, B, C, K = map(int, input().split())
num = K
score = 0
if A >= num:
    score = A
else:
    num -= A
    score += A
    if B >= num:
        pass
    else:
        num -= B
        score -= num
print(score)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = a
k = k - a

if k > 0:
    k = k - b

if k > 0:
    ans = ans - k

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def max_num():
    a, b, c, k = input().split()
    if k <= a:
        print(k)
    if a < k <= a + b:
        print(a)
    if a+b<k<=a+b+c:
        print(a-(k-a-b))
        
max_num()

Submission status: Wrong Answer

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

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

print(d)

Submission status: Wrong Answer

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

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

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

if C < K and K > 0:
    ans -= C
    K -= C
elif A >= K and K > 0:
    ans -= K
    K = 0

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

nokori = K

if A >= K:
    print(A)
    exit()

else:
    ans += A
    nokori = K - A

    if B >= nokori:
        print(ans)
        exit()
    
    else:
        nokori = nokori - B
        ans = ans - nokori
        print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    A,B,C,K = list(map(int, input().split(' ')))
    
    out = 0
    if A > K:
        out = K
        return
    else:
        nokori = K-A
        if nokori <= B:
            out = A
            return out
        elif nokori > B:
            nokonkori = K - A - B
            out = A - nokonkori
            return out
            
            
            
            
            
out = main()
print(out)

Submission status: Wrong Answer

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

if A >= K:
    print(A)
    exit()
else:
    bc = K - A  # A < K なのでbc >= 1
    #assert bc >= 1
    if B >= bc:
        if A >= C:
            print(A)
            exit()
        else:
            print(-abs(bc-C))
    else:
        # B < bc
        cc = bc - B
        #assert cc >= 1
        print(A - cc)
        exit()

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
    
for i in range(0,C):
    if K == 0:
        break
    ans -= 1
    K -= 1
print(ans)

Submission status: Wrong Answer

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

else:
    if A-C >= 0:
        print(A-C)
        exit()

print(0)

Submission status: Wrong Answer

Solution code:

ABCK = input().split()

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


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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

i = 0
maxSum = 0
while(i<K):
  if(i<A):
    maxSum += 1
  elif(i<A+B):
    maxSum += 0
  elif(i<A+B+C):
    maxSum -= 0
  i+=1
print(maxSum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

a,b,c,k = map(int,input().split())
ans = 0
if k>0:
    ans += a
    k -= min(k,a)
if k>0:
    k-= min(k,b)
if k>0:
    d = min(c,k)
    ans += -1*d
print(ans)

Submission status: Wrong Answer

Solution code:
l=list(map(int,input().strip().split()))[:4]
a,b,c,k=l[0],l[1],l[2],l[3]
sum1=0
sum1+=min(a,k)
k-=min(a,k)
if(k==0):
    print(sum1)
else:
    k-=min(b,k)
    if(k==0):
        print(sum1)
    else:
        sum1=sum1-min(a,k)
        print(sum1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Max=0

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

print(Max)

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

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

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

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

print(ans-k)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

ans = 0

if(K<=A):
    ans = A

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

print(A - (K - (A + B)))

Submission status: Wrong Answer

Solution code:
import sys

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

cnt=0


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

if k<=(a+b):
  print(a)
  sys.exit()


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def calculate(a,b,c,k):
    if k<= a+b:
        print(a)
    else:
        if k <= a + b + c:
            print(a - (k - (a+b)))
        else:
            print(a-c)

calculate(A,B,C,K)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys


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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# ABC167 B

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

elif A<n:
	result = A
	n -= A
	if B < n:
		result -= n-B
	print(result)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    a,b,c,k = map(int,input().strip().split())
    print( a-max(0,k-a-b)  )


if __name__ == '__main__':
    main()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def mysum(A, B, C, K):
  if K <= A:
    return(K)
  
  if K <= A+B:
    return(A)
  
  return(A+ -1*(A+B+C-K))
 
print(mysum(A, B, C, K))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,c,k=map(int, input().split())
    l=[]
    if k<=a:
        print(k)
    elif a<k<=a+b:
        print(a)
    else:
        print(max(0,a-(k-(a+b))))
resolve()

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 == 0:
  print(0)
elif A >= K:
  print(A)
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 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())
if k <= a + b:
    print(a)
elif k <= a + b + c:
    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:
a, b, c, k = (int(i) for i in input().split())  

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b,c,k = readInts()
    a_ = k - a
    if a_ <= 0:
        print(a)
    elif a_ > 0:
        a__ = a_ - b
        if a__ <= 0:
            print(a)
        else:
            a___ = a__ - c
            print(max(0,a - a_))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

ans=0

ans+=min(A,K)
K-=A
K-=B
ans-=min(K,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:
    S = K-A-B
    print(A-S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

# 一行に文字列が一個 * n行
s_lis=[readline().rstrip().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換
# 一行に文字列が一個 * n行で文字列をアルファベット順に変換
s_lis=["".join(sorted(readline().rstrip().decode())) for _ in range(n)]
# 一行に文字列が複数個 * n行
s_lis=[readline().rstrip().split().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換

# 一行に数値が一個 * n行
s_lis=[int(readline().rstrip()) for _ in range(n)] 
# 一行に数値が複数個 * n行
s_lis=[int(readline().rstrip().split()) for _ in range(n)]

# dとAの行が交互に並んでいる場合
s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""

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

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

else:
    print(a+b-c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
I = list(map(int,input().split()))
A = I[0]
B = I[1]
C = I[2]
K = I[3]
if A >= K :
    S = A
elif A+B >=K :
    S = A
else:
    S = A - (K-A-B)

print(S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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