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=list(map(int,input().split()))
if A+B>=K:
  print(A)
  exit()
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 = map(int, input().split())

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

print(sum)

Submission status: Wrong Answer

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


n_sum = 0
n_sum += a
k -= a
k -= b
while c > 0:
  c -= 1
  k -=1
  if k < 0:
    break
  n_sum -=1
       
print(n_sum)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int,input().split())
# 1 0 -1 Num
result = 0
if K <= A + B:
	print(A)
else:
	x = K-A-B
	if C < x:
		print(0)
	else:
		print(A-x)

Submission status: Wrong Answer

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


if A+B>K:
    ans = A
else:
    ans += A
    count = K-A-B
    for i in range(count):
        ans-=1
        
    
print(ans)

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 and k < c:
    ans = ans - k
else:
    ans = ans - c

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

a, b, c, k = [int(_) for _ in stdin.readline().rstrip().split()]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = min(A, K)
b = max(K - a, 0)
c = max(K - a - b, 0)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if(a==0 and b==0 and c==0):
  print(0)
elif(k<=a):
  print(a)
elif(a<k<=(a+b)):
  print(a)
elif(a+b<k<=(a+b+c)):
  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:
a,b,c,k = map(int,input().split())
d = k-(a+b)
if a+b >= k:
  print(a)
else: 
  print(a-d)

Submission status: Wrong Answer

Solution code:
import sys


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


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

Submission status: Wrong Answer

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

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

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

if k - c <= 0:
    print(max(a - c , 0))
    exit()

print(a - k)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if a <= k:
    sum += a
    k -= a
else:
    sum +=k
    
if k > 0:
    k -= b
    if c <= k:
        sum -= c
        k -= c
    else:
        sum -= k

print(sum)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    K -= A
    if K <= 0:
        print(min(A, K))
        exit()

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
one,zero,minus,k = map(int,input().split())
result = 0
if one >= k:
    print(k)
else:
    if k >= one and one > 0:
        result += one
        k -= one
    if zero >= k:
        print(result)
    else:
        if k >= zero and zero > 0:
            k -= zero
            if minus > 0:
                print(result-k)

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())
ans = 0

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

elif A < K <= A + B:
    print(A)

else:
    print(A+B-C)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int,input().split())
# 1 0 -1 Num
result = 0
if K <= A + B:
	print(A)
else:
	x = K-A-B
	if C < x:
		x = C
	print(A-x)

Submission status: Wrong Answer

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

ans = 0
cards = [a, b, c]
nums =  [1, 0, -1]

i = 0

while k>0:
    if cards[i] <= k:
        ans += cards[i] * nums[i]
        k -= cards[i]
    else:
        ans += nums[i] * k
        print('cards[i], ans,', cards[i], ans)
        break
    i += 1

print(ans)

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

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

Submission status: Wrong Answer

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

ans+=a
cnt-=a
if cnt<b:
    cnt=0
else:
    cnt-=b
if cnt<c:
    ans-=cnt
else:
    ans-=min(cnt,c)

print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, K = list(map(int, input().split(" ")))
sumv = 0
sumv += A
remain = K - A
use_B = min(B, remain)
use_C = remain - use_B
sumv += (-1* use_C)
print(sumv)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


# 1 x ?,  0 x ?,  -1 x ?
count = 0
if (K <= A + B):
  print(A)
  exit(0)
for i in range(0, K):
  if (A > 0):
    A = A - 1
    count = count + 1
  elif (B > 0):
    B = B - 1
    count = count + 0
  else:
    C = C - 1
    count = count + (-1)
print(count)

Submission status: Wrong Answer

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

s += a
k -=a
k -=b
s -= max(k , 0)
print(s  )

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys

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


one = a
min =0
k = k-a
if k > 0:
    zero = b
    k= k -b

if k > 0:
    min = k

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = 0

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

Submission status: Wrong Answer

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

ans=0
if A<=K:
    ans+=A
if A>K and A!=0:
    ans+=K
    
cntK-=A+B
if cntK>0:
    for i in range(cntK):
        ans-=1
        if ans<0:
            ans=0
            break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
if k > a:
    ans += a*1
    k = k - a
elif a >= k:
    k = 0
    ans = k*1

if k > 0 and k >= b:
    k = k - b
elif k > 0 and k < b:
    k = 0

if k > 0 and k > c:
    ans -= c*1
    k = k - c
elif k > 0 and c >= k:
    ans = ans - 1*k
    k = 0

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def main():
    A,B,C,K = map(int, input().split())
    score=0
    count=K
    i=0
    while count>0:
        if i==0:
            count=count-A
            score=score+A
            # print(score,"s",count)
        elif i ==1:
            count=count-B
            # print(score,"s",count)
        else:
            score=score-count
            count=count-C
            # print(score,"s",count)
        i=i+1
        
    print(score)
main()

Submission status: Wrong Answer

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

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 += k

if b <= k:
    k -= b

if c <= k:
    ans += c
    k -= c
else:
    ans -= k


print(ans)

Submission status: Wrong Answer

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

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


print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

solve()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(total)

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

Submission status: Wrong Answer

Solution code:
import sys

# print('input >>')
A, B, C, K = map(int,(input().split()))

ans = 0
rest = K

rest -= A

if rest <= 0:
    print(A)
    sys.exit()

rest -= B
if rest <= 0:
    print(A)
    sys.exit()

print(K-A-C)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc167/tasks/abc167_b
# -*- coding: utf-8 -*-
A,B,C,K = map(int,input().split())
point = 0
if A+B >= K:
  print(A*1)
else:
  print(A*1 + (K-A-B)*-1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

minus_a = k - a
if minus_a == 0 :
    print(a)
elif minus_a < b :
    print(a)
else:
    minus_c = minus_a - b
    print(a - minus_c)

Submission status: Wrong Answer

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

    K -= A
    if K <= 0:
        print(A)
        exit()

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

if __name__ == "__main__":
    main()

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(lambda x: int(x), input().split())

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import collections
# c = collections.Counter()
#import itertools as it
#import math
#import numpy as np
#import sys 
#sys.exit()
 
#s = input()
#t = input()
#k = int(input())
a,b,c,k = map(int, input().split())
'''
#  = list(map(int, input().split()))
'''
'''
n = input()
a = [int(input()) for i in range(n)]
'''
'''
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
'''
 
#-------------------------------#
#len(t)==len(s)+1
print(a,b,c,k)
if a+b>=k:
    print(a+b)
else:
    print(a+b-a+b-k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

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

k = k-a-b

if k >= c:
    ans -= c
else:
    ans -= k

print(ans)

Submission status: Wrong Answer

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

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

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

a,b,c,k=mii()


ans=0

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

s += a
k -=a
k -=b
s -= max(k , 0)
print(s % ( 10**9 + 7 ) )

Submission status: Wrong Answer

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

tmp = K
maxSum = 0
i = 0
if(tmp>A):
  maxSum+=A
  tmp-=A
else:
  maxSum+=K
  tmp = 0

if(tmp>B):
  tmp-=B
else:
  tmp = 0
  
if(tmp>C):
  maxSum-=C
  tmp-=C
else:
  maxSum-=K-A-B
  tmp = 0
  
print(maxSum)

Submission status: Wrong Answer

Solution code:
import sys


try:
    sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
    sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
    pass


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

    if 1 <= k <= a + b:
        return a
    
    if k > a + b:
        diff = k - a - b
        return a - diff

print(solve())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

print(total + (-1 * k))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


print(ans)

Submission status: Wrong Answer

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

s = K - A
m = 0
if s >= 0:
  m += A
else:
  print(K)

if s - B >= 0:
  s -= B
else:
  print(m)

if s - C >= 0:
  print(m + (-C))
else:
  print(m - s)

Submission status: Wrong Answer

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

ans = 0
if K >= A:
    ans += (A)*1
    K -= A
    judge = 1
else:
    ans += A*1
    judge = 0



if judge==1 and K-B>0:
    K -= B
    judge = 1
elif judge==1 and K-B<=0:
    K-=B
    judge = 0


if judge==1:
    ans += K*-1

print(ans)

Submission status: Wrong Answer

Solution code:
d=input()
d1=d.split()
a=int(d1[0])
b=int(d1[1])
c=int(d1[2])
x=int(d1[3])
if a+b>=x:
    print(a)
if a+b<x:
    print(a-(x-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 + B - C)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

A = a
B = 0
C = -1 * c

if k - a > 0:
    if k -a -b > 0:
        print(a + b -(k -a - b))
        sys.exit()
    else:
        print(a)
else:
    print(k)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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


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

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

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

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

Submission status: Wrong Answer

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

ans = 0

for i in range(A):
  if(K>0):
    ans = ans + 1
    K = K-1
for i in range(B):
  if(K>0):
    ans = ans 
    K = K-1
for i in range(C):
  if(K>0):
    ans = ans - 1
    K = K-1

Submission status: Wrong Answer

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

point = 0

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(ans)
if sum_AB<=K:
    ans-=K-A-B


print(ans)

Submission status: Wrong Answer

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


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

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


if __name__ == "__main__":
    import sys

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

Submission status: 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)))