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:


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

Submission status: Wrong Answer

Solution code:

s = list(map(int,input().split()))
a=s[0]
b=s[1]
c=s[2]
k=s[3]
if a+b<k:
    print(a-(k-a-b))
else:
    print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    a, b, c, k = map(int, input().split())
    ans = 0
    if k < a:
        ans = k
    elif a <= k <  b:
        ans = a
    elif b <= k < c:
        ans = a
    else:
        ans = a - (k - a - b)
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if k > 0:
  ans += a
  k -= a

if k > 0:
  k -= b

if k > 0:
  ans -= k

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

res = 0
if (A >= K):
    print(A)
    quit()
else:
    K -= A
    res += A



if (B >= K):
    print(res)
    quit()
else:
    K -= B

res += - min(C, K)

print(res)

Submission status: Wrong Answer

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

x=0
y=0
if(a>k):
    x=k
    k=0
else:
    x=a
    k=k-a
if(b>k):
    k=0
else:
    k=k-b
if(c>k):
    y=k
    k=0
print(x-y)

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

s=0
if a>=k:
    s=k
elif b>=k-1:
    s=a
else:
    s=a-(k-a-b)

print(s)

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

Submission status: Wrong Answer

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

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

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

if K > 0:
    n = min(B, K)
    K = K - n

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

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 20:54:25 2020

@author: Kanaru Sato
"""

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x = k - a
res = a
if x > 0:
    x = x - b
    if x > 0:
        res -= x

print(res)

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 K < A:
    print(A)
elif A < K and 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:
    print(max(A, K))
elif K <= A + B:
    print(A)
else:
    remain_K = K - (A + B)
    print(A - remain_K)

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

Submission status: Wrong Answer

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

K-=B
if K>0:
    pass
else:
    print(A)
    exit()

K-=C
if K>0:
    ans -= C
    print(ans)
else:
    ans -= (K+C)
    print(ans)

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k = list(map(int,input().split()))
s = 0
while a>0 or k>0:
  s+=1
  k-=1
  a-=1

while b>0 or k>0:
  s+=0
  k-=1
  b-=1

while c>0 or k>0:
  s-=1
  k-=1
  c-=1

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = 0

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

if 0 < k <= b:
    k = 0
else:
    k -= b

result -= k
k= 0

print(result)

Submission status: Wrong Answer

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

if K <= A:
    ans = K
elif K <= A + B:
    ans = A
else:
    ans = A - K + C

print(ans)

Submission status: Wrong Answer

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

ans-=k
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():

    input = stdin.readline

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

    sum_num = 0
    ans_num = 0

    if A >= K:
        ans_num += A
    else:
        sum_num += A
        ans_num += A
        if B >= K + sum_num:
            pass
        else:
            ans_num -= (K - A - B)
        
    print(ans_num)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

print(A - max(0, (K - A - B)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    A,B,C,K=pin()
    ans=A
    K-=(A+B)
    if K<0:print(ans);return
    print(ans-K)
#%%submit!
resolve()

Submission status: Wrong Answer

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

ans = A + B
value = A + B*0
if ans >= K:
    print(value)
else:
    value -= K - ans
    print(value)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = K - A
b = a - B
c = 0
if b > 0:
    c = K - b


print(max(A - c, 0))

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:
def linear(a, b, c, k):
  count = 0
  if(k>a):
    count+=a
    k-=a
    if(k>b):
      count-=(k-b)
    return count
  else:
    return a

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

Submission status: Wrong Answer

Solution code:
s=input().split()
a=int(s[0])
b=int(s[1])
c=int(s[2])
k=int(s[3])
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 >= K:
    print(A)
elif (A+B) >= K:
    print(A)
else:
    tmp = K-(A+B)
    print(A-tmp)

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
a,b,c,k = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
if k >= a:
    ans += a
    k -= a
if k >= b:
    k -= b
if k >= 0:
    ans -= k
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

a,b,c,k = MI()

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

Submission status: Wrong Answer

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

print(a)

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)
else:
    print(a-(k-a-b))

Submission status: Wrong Answer

Solution code:
import sys, re
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 heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, K = MAP()

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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

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

for i in range(k):
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-05-10 20:03
# @url:
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    abck=list(map(int,input().split()))
    a,b,c,k=abck[0],abck[1],abck[2],abck[3]
    if k<=a+b:
        print (a)
    else:
        x=k-(a+b)
        print (a-x)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
count=0
ans = 0
for i in range(k):
    if count <= a:
        ans += 1
        count += 1
    if a<count<= a+b:
        count += 1
    if a+b <count <= a+b+c:
        ans-=1
        count += 1

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math
#def main(S, b):
if __name__ == '__main__':
    a, b, c, k = map(int, input().split())

    # x = int(input())
    #a, b = map(int, input().split())

    # a = list(map(int, input().split()))

    # s = input()
    # t = input()

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

    # if (s == t[:(len(s))] and len(t) == len(s) + 1):

    #     print("Yes")
    # else:
    #     print("No")
    # s = sum(a)

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:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
a, b, c, k = map(int, input().split())
if (a + b) > k:
    print(a)
else:
    print((a) - min(k, c))

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

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    a, b, c, k = ns()
    if a + b < k:
        ans = a - (k - a - b)
    elif k > a:
        ans = a
    else:
        ans = a

    print(ans)


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

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, K = il()
    print(max(0, 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+B>=K:
    print(A)
else:
    print(A+(A+B-K))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

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

else:
    cnt += a
    

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,c,k = mi()

ima = k

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

ima = k - a

if b >= ima:
    print(a)
    exit()

ima = ima - b

nokori = min(c,ima)
print(a-nokori)

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(a,b,c,k):
    res = 0
    if k <= a:
        res = k
    if a < k <= a+b:
        res = a
    else:
        res = a - (k - (a+b))
    return res

a,b,c,k = mi()
print(main(a,b,c,k))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
A, B, C, K = M()
ans = 0
if A < K:
    ans += A
    K -= A
    if B < K:
        K -= B
        ans -= K
else:
    ans = A
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 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 A >= K: print(A)
elif A + B >= K: print(A)
else: print(A + B - C)

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