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())
 
ans = 0
if K-A>0:
    ans += (A)*1
    K -= A
    judge = 1
else:
    ans += A*1
    judge = 0
 
 
 
if judge==1 and K-B>0:
    K -= B
    judge = 1
else:
    K-=B
    judge = 0
 
 
if judge==1:
    ans += K*-1
 
print(ans)

Submission status: Wrong Answer

Solution code:
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

# --- fetch input ---
inputs: list = []
while True:
    try:
        inputs.append(input().strip('\n'))
    except EOFError:
        break

# --- write code below ---
a, b, c, k = map(int, inputs[0].split())

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

Submission status: Wrong Answer

Solution code:
input_list = input().split(" ")
a = int(input_list[0])
b = int(input_list[1])
c = int(input_list[2])
k = int(input_list[3])
total = a + b + c
if k >= 1 and k <= total and total <= 2000000000:
    temp = a + b
    if a >= k and temp >= c:
        print(a - (k -a))
    elif c >= a:
        print(0)
    elif temp == k:
        print(a)
    else:
        aa = k - a
        ab = aa - b
        ac = ab - c
        if ac > 0 and a > c:
            print(a - c)
        elif ac >0 and c > a:
            print(c - a)
        elif ac < 0 and temp >= c:
            aa = k - temp
            ab = c - aa
            print(temp - ab)
        elif ac < 0 and temp <= c:
            print(0)
        else:
            print(a - c)
else:
    print()

Submission status: Wrong Answer

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

score=0

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
a, b, c, k = map(int, input().split())
max = 0
if a >= k:
    print(a)
    sys.exit()
else:
    for i in range(b, -1, -1):
        for j in range(c):
            if a+i+j == k:
                print(a-j)
                sys.exit()

Submission status: Wrong Answer

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

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:
######ANSDEFINE##########
#unnecessary			#
#########################

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

if A <= K: #AがKより小さい
  
  if A + B >= K: #A+BがKより大きい
    print(A * 1)
    
  elif A + B <= K: #A+BがKより小さい
    if B >= 1: #Bが1枚以上
      if A+B >= C:#A+BがCより小さい
        print((A+B) - C)
      else:#それ以外
        print((A+B) - C)
    else: #それ以外
      print(A - C)
     
	
elif A >= K: #AがKより大きい
  print(A *1)

Submission status: Wrong Answer

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

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

print(num)

Submission status: Wrong Answer

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

sum = 0
if K >= A:
    for i in range(A):
        sum += 1
else:
    for i in range(K):
        sum += 1
        break

    if (K-A) >= B:
        for i in range(B):
            sum += 0
    else:
        for i in range(K-A):
            sum += 0
            break

        if (K-(A+B)) >= C:
            for i in range(C):
                sum += -1
        else:
            for i in range(K-(A+B)):
                sum += -1
                break

print(sum)

Submission status: Wrong Answer

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

nokori = K - A - B

wa = 0
wa += A

if C >= nokori:
    wa -= nokori
else:
    wa -= C

print(wa)

Submission status: Wrong Answer

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

print (A, B, C, K)

sum = 0

if K - A >= 0:
  K -= A
  sum += A
else:
  print(sum)
  exit

if K - B >= 0:
  K -= B
  sum += 0
else:
  sum += 0
  print(sum)
  exit

if K - C >= 0:
  K -= C
  sum += -C
else:
  sum += -1 * K

print (sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve(A, B, C, K):
    if K <= A:
        return 1 * A

    num = K - A
    ans = 1 * A

    if num <= B:
        return ans

    num -= B

    if num < 0:
        return ans

    return ans - num


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

if a == 0:
    print(0)
if a == 0 and b == 0:
    print(0)

if k < a:
    print(k*1)

ans = a*1
k -= a

if k > 0:
    k -= b
    
    if k > 0:
        for _ in range(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())

max = 0
for i in range(A):
    max+=1
    K-=1
    if K ==0:
        break
        


for j in range(B):
    max+=0
    K-=1
    if K ==0:
        break
    
for k in range(C):
    max-=1
    K-=1
    if K ==0:
        break
    
print(max)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

out = deque()
for i in [A,B,C]:
    if(i <= K):
        out.append(i)
        K = (K - i) if (K - i) >= 0 else K
    else:
        out.append(((K - i) if (K - i) > 0 else K))

print(1*out[0] + 0*out[1] + (-1)*out[2])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
A, B, C, K = map(int, input().split())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
from bisect import bisect_left, bisect_right, insort
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 MS(): return map(str,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())
#N = I()
#A = [LI() for _ in range(N)]

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

Submission status: Wrong Answer

Solution code:
s = input().split()

if s[3] == "0" :
    print(0)
    
elif ( int(s[0]) >= int(s[3]) ) or ((int(s[3]) - int(s[0]) <= int(s[1]))) :
    print(s[0])
elif int(s[3]) - int(s[0]) > int(s[1]) :
    print(int(s[0])- (int(s[3])-int(s[0])-int(s[1])))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# B - Easy Linear Programming
def main():
    
    a, b, _, k = map(int, input().split())
    ans = a
    if k > a:
        k = k - a
        if k > b:
            k = k - b
            ans -= k
            print(ans)
        else:
            print(ans)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
num = input().split()
A = int(num[0]) #1
B = int(num[1])  #0
C = int(num[2]) #-1
K = int(num[3]) #選ぶ個数

count = 0
kai = 0
if K >= A:
    kai = A
    count = A
    
    if count < K:
        if K >= A+B:
            kai = A
            count = A+B
            
            if count < K:
               kai = A + (K - count)*(-1)
               
print(kai)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
card    = list(map(int, input().split()))
count  = card[3] - card[0] - (card[1])
answer = card[0]

if count <= 0:
    print(answer)
else:
    count -= card[2]
    answer -= count * -1
    print(answer)

Submission status: Wrong Answer

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

count = K
ans = 0


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

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

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())
num = a
k -= a

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

print(num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = input().rstrip().split(' ')
A,B,C,K = int(a[0]),int(a[1]),int(a[2]),int(a[3])
s = 0

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

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

Submission status: Wrong Answer

Solution code:
a,b,c,k = map(int,input().split())
ka = k - a
kab = k-a-b
def choice(a,ka,kab,k):
    if ka <= 0:
        return a
    elif kab <= 0:
        return a
    else:
        return a-kab

print(choice(a,ka,kab,k))

Submission status: Wrong Answer

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

sum =0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(n)

Submission status: Wrong Answer

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

ans = 1 * a
count = d - a

if count - b > 0:
  ans = ans + 0 * b
  count = count - b
  
if count - c > 0:
  ans = ans -1 * c
  
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

for i in range(A):
        for j in range(B):
            for k in range(C):
                max+=1
                K-=1
                if K==0:
                    break
            else:
                continue
            break
        else:
            continue
        break
      
print(max)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def get_result(data):
    A, B, C, K = data
    if (A + B) >= K:
        return A
    else:
        return A - (K-(A+B))


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

Submission status: Wrong Answer

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

A = 0
if (a<d):
  if (c < (d-a-b)):
    A = a-c
  else:
  	A = a
else:
  A = d
print(A)

Submission status: Wrong Answer

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

print(n)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
Ts = 0
sA = K - A
if sA > 0:
    sB = sA - B
    if sB > 0:
        sC = sB - C
        if sC < 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
        elif sC == 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
    elif sB == 0:
        Ts = ((K - sA) * 1) + (sB * 0)
    else:
        Ts = ((K - sA) * 1) + ((sA - sB) * 0)
elif sA == 0:
    Ts = A * 1
else:
    Ts = sA * 1
print(Ts)

Submission status: Wrong Answer

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

score=0

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

Submission status: Wrong Answer

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

print(sum)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

out = []
for i in [A,B,C]:
    if(i <= K):
        out.append(i)
        K = (K - i) if (K - i) >= 0 else K
    else:
        out.append(((K - i) if (K - i) > 0 else K))

# if len(out) < 3:
#     for i in range(3 - len(out)):
#         out.append(0)

print(1*out[0] + 0*out[1] + (-1)*out[2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
######ANSDEFINE##########
#unnecessary			#
#########################

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

if A <= K: #AがKより小さい
  
  if A + B >= K: #A+BがKより大きい
    print(A * 1)
    
  elif A + B <= K: #A+BがKより小さい
    if B >= 1: #Bが1枚以上
      if A+B >= C:#A+BがCより小さい
        print((A+B) - C)
      else:#それ以外
        print("0")
    else: #それ以外
      print(A - C)
     
	
elif A >= K: #AがKより大きい
  print(A *1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count, score = 0, 0

score += A
count += A
if count < K:
    c = min(B, (K - count))
    score += 0 * c
    count += c

    if count < K:
        c = min(C, (K - count))
        score += -1 * c
        count += c

print(score)

Submission status: Wrong Answer

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

count = 0

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

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, k = map(int, input().split())
if (a+b) < k:
    print((a+(b*0))-(k-(a+b)))
else:
    print(a)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

sum=0
T=K
if T>A:
    sum=A
    T=T-A
    if T > B:
        T = T - B
        sum = sum - T
        print(int(sum))

    else:
        print(int(sum))

else:
    sum=A
    print(int(sum))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# B - Easy Linear Programming
def main():
    
    a, b, _, k = map(int, input().split())
    ans = a
    if k >= a:
        k = k - a
        if k >= b:
            k = k - b
            ans -= k
            print(ans)
        else:
            print(ans)
    else:
        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)
elif k <= a+b:
    print(a)
elif k <= a+b+c:
    print(a + (k-a-b)*(-1))

Submission status: Wrong Answer

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

out = []
for i in [A,B,C]:
    if(i <= K):
        out.append(i)
        K = (K - i) if (K - i) >= 0 else K
    else:
        out.append(((K - i) if (K - i) > 0 else K))

print(1*out[0] + 0*out[1] + (-1)*out[2])

Submission status: Wrong Answer

Solution code:
a,b,c,k=(int(n) for n in input().split())
sum = 0
if a >= k:
    sum = a
elif b+a >= k:
    sum = a
else:
    sum = a - (k-a-b)

print(sum)

Submission status: Wrong Answer

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

count = 0
x = 0

x = K - A
count = A * 1

if x >= 0:
    x = x - B
    if x >= 0:
        C = K - A - B
        count = count + C * -1

print(count)

Submission status: Wrong Answer

Solution code:
card    = list(map(int, input().split()))
count  = card[3] - card[0] - (card[1])
answer = card[0]

if count < card[2]:
    print(answer)
else:
    count -= card[2]
    answer -= count * -1
    print(answer)

Submission status: Wrong Answer

Solution code:
A,B,C,K = input().split()
a = int(A)
b = int(B)
k = int(K)

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

Submission status: Wrong Answer

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


ka = k - a
if k > 0:
    kb = ka - b
print(a*1+ka*0+kb*-1)

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

ans -= k

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k=(int(x) for x in input().split())
a1 = a
tensuu = 0
count = 0
if k-a1 > 0:
   tensuu +=a1
else:exit()

if k-a1 >0:
    count = k-(a1+b)

else:exit()

if k-a1-b > 0 :
    tensuu -=count

print(tensuu)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
a,b,c,k=(int(n) for n in input().split())
sum = 0
if a >= k:
    sum = a
elif b+a >= k:
    sum = a
else:
    sum = a - (k-a-b)

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=input().split()
pl1=int(a[0])
pl0=int(a[1])
pl_1=int(a[2])
draw=int(a[3])
#print(pl1,pl0,pl_1,draw)
if(pl1>=draw):
  print(draw)
elif(pl1+pl0>=draw):
  print(pl1)
else:
  all_card=pl1+pl0+pl_1
  #print(all_card)
  draw_pl_1=all_card-pl1-pl0
  #print(draw_pl_1)
  print(pl1-draw_pl_1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(sum)

Submission status: Wrong Answer

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

a_times = 0
b_times = 0
c_times = 0

if a <= k:
    a_times = a
    # print('a_times = ', a_times)
if a + b <= k:
    b_times = k - a
    # print('b_times = ', b_times)
else:
    b_times = k - a - b
    # print('b_times = ', b_times)
if a + b + c <= k:
    c_times = k - a - b
    # print('c_times = ', c_times)
else:
    c_times = k - a - b
    # print('c_times = ', c_times)

print(a_times * 1 + b_times * 0 + c_times * -1)

Submission status: Wrong Answer

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

hash_table = {
    1: a,
    0: b,
    - 1: c,
}
ans = 0
for ele in hash_table:
    k = k - hash_table[ele]
    if k >= 0:
        ans += hash_table[ele] * ele
    else:
        ans += abs(hash_table[ele]+k) * ele
print(ans)

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 = input().split()
a = int(a)
b = int(b)
c = int(c)
k = int(k)


max_val = 0

x = k - a
if x >= 0:
    max_val = max_val + a * 1
    k = x
elif x < 0:
    k = 0
    max_val = max_val + k * 1


if k > 0:
    x = k - b
    if x >= 0:
        max_val = max_val + b * 0
        k = x
    elif x < 0:
        k = 0
        max_val = max_val + k * 0


if k > 0:
    x = k - c
    if x >= 0:
        max_val = max_val + c * -1
    elif x < 0:
        max_val = max_val + k * -1

print(max_val)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
P = 0
S = 0
while S==0:
    P += A
    K -= A
    if K < 0:
        P = K
        break
    elif K == 0:
        break

    K -= B
    if K <= 0:
        break

    P -= C
    K -= C
    if K <= 0:
        P += abs(K)
        break
    S=1
print(P)

Submission status: Wrong Answer

Solution code:
A,B, C,K = input().split()
Q = int(0)
Y = int(1)
for Y in range(int(K)):
    X = int(A) - Y
    Z = int(B) -X
    W = int(C) -Z
    if X >0 and Z >0 and W >=0:
        print(int(B)+2*int(A)-int(K))
    elif X >=0and Z ==0:
        print(int(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def actual(A, B, C, K):
    print('\n')

    if K <= A:  # いきなり解決
        return A

    score = 0

    if K > A:
        score += A
        K -= A

    if K <= B:
        return score

    if K > B:
        K -= B

    # ここからは K <= C が確定している
    # 残りの選択回数分だけ減らせばよい
    score -= K

    return score

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

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

Submission status: Wrong Answer

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

if K >= A:
	sum = A
	K = K - A
else:
	while A >= 1 and K >= 1:
		sum = sum + 1
		A = A - 1
		K = K - 1
if K >= B:
	K = K - B
else:
	while B >= 1 and K >= 1:
		B = B - 1
		K = K - 1
while C >= 1 and K >= 1:
	sum = sum -1
	C = C - 1
	K = K - 1

if sum >= 1:
	print(sum)
else:
	print(0)

Submission status: Wrong Answer

Solution code:
A, B, C, K = [int(i) for i in 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())

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


sum=0
#print('K : ' + str(K) + '   SUM : ' + str(sum))

if K > A :
	sum+=A
else:
	sum+=K
K-=A
#print('K : ' + str(K) + '   SUM : ' + str(sum))
if K > 0:
	if K > B :
		sum+=B
	else:
		sum+=K

	K-=B
	#print('K : ' + str(K) + '   SUM : ' + str(sum))

	if K > 0:
		sum-=K
		#print('K : ' + str(K) + '   SUM : ' + str(sum))

print(sum)

Submission status: Wrong Answer

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

out = []
for i in [A,B,C]:
    if(i <= K):
        out.append(i)
        K = (K - i) if (K - i) >= 0 else K
    else:
        out.append(((K - i) if (K - i) > 0 else K))

if len(out) < 3:
    for i in range(3 - len(out)):
        out.append(0)

print(1*out[0] + 0*out[1] + (-1)*out[2])

Submission status: Wrong Answer

Solution code:
A,B,C,K=(int(x) for x in input().split())
res = A
les = A+B
if K>les:
  los = K-les
  res -= los
print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin

A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
countA = 0
countB = 0
countC = 0
# for i in range(1, K+1):
#     print(i)

for i in range(1, A+1):
    K -= 1
    countA += 1
    if K == 0:
        break

print(countA)
print(K)

if K == 0:
    print(int(countA*1))

for i in range(1, B+1):
    K -= 1
    countB += 1
    if K == 0:
        break

if K == 0:
    print(int(countA*1 + countB*0))

for i in range(1, C+1):
    K -= 1
    countC += 1
    if K == 0:
        break

if K == 0:
    print(int(countA*1 + countB*0 + countC*-1))

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

Submission status: Wrong Answer

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




ka = k - a
kb = ka - b
print(a*1+ka*0+kb*-1)

Submission status: Wrong Answer

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

max_sum = 0

if a+b < k:
    max_sum = a+b-c
else:
    max_sum = a

print(max_sum)

Submission status: Wrong Answer

Solution code:
s = input().split()

if ( int(s[0]) >= int(s[3]) ) or ((int(s[3]) - int(s[0]) <= int(s[1]))) :
    print(s[0])
elif int(s[3]) - int(s[0]) > int(s[1]) :
    print(int(s[0])- (int(s[3])-int(s[0])-int(s[1])))

Submission status: Wrong Answer

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


def function(a,b,c,k):
    count =0
    if a>=k:
        return a
    else:
        count =a
        k =k-a
        a=0
        if b>=k:
            return count
        else:
            k-=b
            b=0
            count-=k

        return count
print(function(a,b,c,k))

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
n = a[0]
m = a[1]
l = a[2]
k = a[3]

if 0 < n < k:
    print(n)

elif n + m >= k:
    print(n)
    
elif n + m + l >= k:
    print(n -1*(k-l))
else:
    print(0)

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:
A,B,C,K=map(int,input().split())
U=0
E=0
D=0
U=A-K
U=K-U
E=K-A
D=K-E
if U>=0:
    print(K)
elif D>=0:
    print(D)
else:
    for i in range(0,C):
        D=D+-1
        
print(D)