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: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	a, b, c, k= IN()
	#s = input()
	if k <= a:
		return k
	elif k <= a+b:
		return a
	else:
		m = k - a - b
		return a - m
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__=="__main__":
    main()

Submission status: Accepted

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

if k > a:
    ans+=a
    k-=a
    if k > b:
        k-=b
        if k > c:
            ans-=c
        else:
            ans-=k
else:
    ans+= k

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def main():
    A, B, C, K = map(int, open(0).read().split())

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


main()

Submission status: Accepted

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

if a >= k:
    print(k * 1)
    sys.exit()
elif k > a:
    if a + b >= k:
        print(a * 1)
        sys.exit()
    elif k > a + b:
        print(a * 1 + (k - a - b)* -1)
        sys.exit()

Submission status: Accepted

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

Submission status: Accepted

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

s = 0
b = [1, 0, -1]
for i, j in enumerate(a):
    n = min(j, k)
    k -= n
    s = s + b[i]*n
    if k<=0:
        break
print(s)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
A_1, B_0, C_minus1, K = map(int, input().split(' '))

max_total = 0

if(K <= A_1):
  max_total = K
elif(K > A_1 and K <= (A_1 + B_0)):
  max_total = A_1
else:
  left = K - (A_1 + B_0)
  if(left <= C_minus1):
    max_total = A_1 - left
  else:
    max_total = A_1 - C_minus1
  
print(max_total)

Submission status: Accepted

Solution code:
if __name__=="__main__":
    num_plus_one, num_zero, num_minus_one, total_num = map(int, input().split(' '))

    if total_num <= num_plus_one:
        counter = total_num
    elif total_num <= num_plus_one + num_zero:
        counter = num_plus_one
    elif total_num <= num_plus_one + num_zero + num_minus_one:
        counter = num_plus_one - (total_num - num_plus_one - num_zero)
    else:
        counter = num_plus_one - num_minus_one

    print(counter)

Submission status: Accepted

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

R = 0
if A >= K:
  R = K
  K = 0
else:
  R = A
  K -= A
#
if B >= K:
  K = 0
else:
  K -= B
#
if C >= K:
  R -= K
else:
  R -= C
#
print(R)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8
def main():
    A, B, C, K = map(int, input().split())
    s = 0
    s += min(A, K) * 1
    K = max(K - A, 0)
    s += min(B, K) * 0
    K = max(K - B, 0)
    s += min(C, K) * -1
    print(s)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
l = list(map(lambda x:int(x), input().split(" ")))
a = l[0]
b = l[1]
c = l[2]
k = l[3]
if a >= k:
    print(k)
elif a < k:
    if b >= k-a:
        print(a)
    elif b < k-a:
        print(a-(k-a-b))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,N = map(int,input().split())
sum_card = [A,B,C]
for i in range(2):
    sum_card[i+1] += sum_card[i]
if(N<A):
    print(N)
elif(N-sum_card[1]<=0):
    print(A)
elif(N-sum_card[1]>0 and C - (N-sum_card[1])>0):
    print((N-sum_card[1])*(-1)+A)
elif(N>=sum_card[2]):
    print(A-C)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if k >= a:
    sum += a
else:
    sum += k
    print(sum)
    exit()

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

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

print(sum)

Submission status: Accepted

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

if A <= K:
    ans = 1 * A
    K = K - A
else:
    ans = K
    print(ans)
    exit(0)

if 0 < K:
    ans = ans + 0 * B
    K = K - B

if 0 < K:
    ans = ans + (-1) * K

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


def main():
    A, B, C, K = [int(x) for x in input().split()]
    if K > A+B:
        print(A - (K-(A+B)))
    elif K < A:
        print(K)
    else:
        print(A)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

AA = 0
BB = 0
CC = 0
Nokori = K 
if Nokori >= A:
    AA = A
    Nokori = Nokori - A
elif Nokori == 0:
    pass
else:
    AA = Nokori
    Nokori = 0
if Nokori >= B:
    BB = B
    Nokori = Nokori - B
elif Nokori == 0:
    pass
else:
    BB = Nokori
    Nokori = 0
if Nokori >= C:
    CC = C
elif Nokori == 0:
  pass
else:
    CC = Nokori
print(AA*1+BB*0+CC*(-1))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def linear(A, B, C, K):
    s = 0
    if K <= A:
        return K

    s += A
    K -= A


    if K <= B:
        return s

    K -= B

    return s - K

if __name__ == "__main__":
    A, B, C, K = map(int, input().split())
    print(linear(A, B, C, K))

Submission status: Accepted

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

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

if A == 0 and B == 0:
    print(-1*K)
    exit()

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

print(a+c)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
result = min([A, K])
K -= result
if K != 0:
  K -= min([B, K])
if K != 0:
  result -= min([C, K])
print(result)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
if k <= a:
    k_pa, k_pb, k_pc = k , 0, 0 
elif k > a and k-a <= b:
    k_pa, k_pb, k_pc = a, b, 0
elif k > a and k-a > b:
    k_pa, k_pb, k_pc = a, b, k-a-b
point = k_pa - (k-k_pa-k_pb)
print(point)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import numpy as np
import math
from collections import Counter
import sys

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

total = 0

if a >= k:
    print(k)
    sys.exit()
else:
    if a+b >= k:
        print(a)
        sys.exit()
    else:
        if k-(a+b) <= c:
            total = a - (k- (a+b))
            print(total)
            sys.exit()
        else:
            total = a - c
            print(total)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
def create_union_answer(a, b, c, k):
    if a >= k:
        return k
    if a + b >= k:
        return a
    # can select type[c] card numbers.
    can_c = k - (a + b)
    if can_c > c :
        can_c = c
    return a - can_c

values = input().split()

a = int(values[0])
b = int(values[1])
c = int(values[2])
k = int(values[3])

answer = create_union_answer(a, b, c, k)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
idx = 0

if k >= a :
  k -= a
  cnt += a
else:
  cnt += k
  k = 0

if k != 0:
  if k >= b:
    k -= b
  else:
    k = 0

if k != 0:
  if k >= c:
    cnt -= c
    k -= c
  else:
    cnt -= k
    k = 0

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count=0

if k <= a:
    count +=k
elif k <= a+b:
    count +=a
else:
    count = 2*a + b - k

print(count)

Submission status: Accepted

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

ans = 0

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

k = k-a

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


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

print(ans)

Submission status: Accepted

Solution code:
def solve(a, b, c, k):
    if k <= a:
        return k
    elif k <= a + b:
        return a
    else:
        return a - (k - (a + b))

if __name__ == '__main__':
    a, b, c, k = [int(arg) for arg in input().split()]
    print(solve(a, b, c, k))

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
box = []
result = 0

if k <= a:
    print(k)
    quit()
else:
    k = k - a
    result = a
    if k <= b:
        print(result)
        quit()
    else:
        k = k - b
        if k <= c:
            result = result - k
            print(result)
            quit()
        else:
            result = result -c
            print(result)
            quit()

Submission status: Accepted

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

if a - k < 0:
    sc = a
    k = abs(a - k)
else:
    print(k)
    exit()

if b - k < 0:
    k = abs(b - k)
else:
    print(sc)
    exit()

if c - k < 0:
    sc-=c
else:
    sc-=k
print(sc)

Submission status: Accepted

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

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

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

if k > 0:
    if c >= k:
        ans -=k
        print(ans)
        k -=c
    else:
        k -=c
        print(ans)

Submission status: Accepted

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

if K <= 0:
    print(ans)
    exit()
else:
    if K >= C:
        ans += C * -1
        K += K - C
    else:
        ans += K * -1
        K += K - C
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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-K+B)

Submission status: Accepted

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

sum =0 

flg = False

if K-A > 0:
    sum+= A
    K = K- A
else:
    sum += K
    flg = True

    
if flg ==False:
    if K-B > 0:
        K= K-B
    else:
        flg = True
        
if flg ==False:
    if K-C >0:
        sum = sum - C
    else:
        sum = sum - K
        
        
print(sum)

Submission status: Accepted

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

res = min(a, z) - max(0, z - a - b)

print(res)

Submission status: Accepted

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

ans = 0

ans = A
K = K - A

if K < 0:
  ans = ans + K
  print(ans)
  sys.exit(0)

if K > 0:
  K = K - B

if K > 0:
  ans = ans - K

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

while True:
    if (K <= A):
        ans += K * 1
        break
    elif (K > A):
        K -= A
        ans += A * 1
    
    if (K <= B):
        break
    elif (K > B):
        K -= B

    if (K <= C):
        ans -= K * 1
        break
    else:
        ans -= C * 1

    break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
z = input().split()
a = int(z[0])
b = int(z[1])
c = int(z[2])
k = int(z[3])
if(1 <= k <= a+b+c <= 2*(10**9)):
    if(k <= a):
        print(k)
    elif(k <= a+b):
        print(a)
    else:
        print(a - (k-(a+b)))
else:
    print('err')

Submission status: Accepted

Solution code:
s = input().split();
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
k = int(s[3]);
max = 0;
x = a;
if( (a - k) >= 0 ):
    max = k;
elif((a + b - k) >= 0):
    max = a;
else:
    k = k - (a + b);
    max = -k;
    max = max + a;

print(max);

Submission status: Accepted

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

if k>=a:
    score=a
    k=k-a
    if k>=b:
        k=k-b
        if k>0:
            score-=k
else:
    score=k

        
print(score)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

if a>0 and k>0 and a<=k:
  k=k-a
  ans=ans+a
elif a>0 and k>0 and a>k:
  ans=ans+k
  k=0

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

  
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(sys.stdin.readline() for _ in range(n)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

A,B,C,K = map(int,sys.stdin.readline().split())

#ALL = [1]*A+[0]*B+[-1]*C
#print(sum(ALL[:K]))
print(1*min(A,K)+0*min(B,max(K-A,0))-1*min(C,max(K-A-B,0)))

Submission status: Accepted

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

count = 0


if a > 0 and a <= k and k > 0:
  count = count + a
  k = k - a
elif a > 0 and a > k and k > 0:
  count = k
  k = 0

if b > 0 and b <= k and k > 0:
  k = k - b
elif b > 0 and b > k and k > 0:
  k = 0
  
if c > 0 and c <= k and k > 0:
  count = count - c
  k = k - c
elif c > 0 and c > k and k > 0:
  count = count - k
  k = 0
    
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if a > 0:
    if a <= k:
        res += a
        k -= a
    elif a > k:
        res += k
        k = 0

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

if k > 0 and c > 0:
    if c <= k:
        res -= c
        k -= c
    elif c > k:
        res -= k
        k = 0

print(res)

Submission status: Accepted

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

Submission status: Accepted

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
#print(str(tmp) + ' sum = ' + str(maxSum))

if(tmp>B):
  tmp-=B
else:
  tmp = 0
#print(str(tmp) + ' sum = ' + str(maxSum))

if(tmp>C):
  maxSum-=C
  tmp-=C
else:
  maxSum-=tmp
  tmp = 0
#print(str(tmp) + ' sum = ' + str(maxSum))

print(maxSum)

Submission status: Accepted

Solution code:

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

    ans = 0
    cnt = min(K, A)
    ans += cnt * 1
    K -= cnt
    if K < 1:
        return print(ans)

    cnt = min(K, B)
    ans += cnt * 0
    K -= cnt
    if K < 1:
        return print(ans)

    ans += K * -1

    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

info = input().split(' ')
card_one = int(info[0])
card_zero = int(info[1])
card_minus = int(info[2])
number = int(info[3])

sumnum = 0

if (number >= card_one):
    number = number - card_one
    sumnum = sumnum + card_one
else:
    print(number)
    sys.exit()

if (number >= card_zero):
    number = number - card_zero
else:
    print(sumnum)
    sys.exit()

if (number >= card_minus):
    sumnum = sumnum - card_minus
    print(sumnum)
else:
    sumnum = sumnum - number
    print(sumnum)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
x=min(a,k)
y = min(b, k - a)
print(x+(k-a-y)*-1)

Submission status: Accepted

Solution code:
def main(a: int, b: int, c: int, k: int):
    ans = 0

    _a = min(a, k)
    ans += _a
    k -= _a

    if b >= k:
        print(ans)
        return

    _b = min(b, k)
    k -= _b

    _c = min(c, k)
    ans -= _c

    print(ans)


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

Submission status: Accepted

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

print(sum_num)

Submission status: Accepted

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

    


def check(a,b,c,k):
    resutlt = 0
    if a > k:
        result = k
        return result
    else:
        k -=a
        result = a
        if b>k:
            return result 
        else:
            k -= b
            result  -= k
            return result 

print(check(a,b,c,k))

Submission status: Accepted

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


print(num-k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

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

    a = K if A>=K else A
    b = (K-a) if B>=(K-a) else B
    c = K-a-b if C>=(K-a-b) else C
    print(a-c)


main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
a, b, c, k = map(int, input().split())
if a + b <= k:
    print(a - (k - (a + b)))
    exit()
elif a <= k:
    print(a)
else:
    print(k)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():

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

    if K > A:
        num += A
        K -= A
        if K > B:
            K -= B
            num -= K
    else:
        num+=K

    print(num)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
import itertools
A,B,C,K = map(int,input().split())

count=0
if A>=K:
    ans=K
else:
    count+=A
    if A+B>=K:
        ans=A

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

max  = 0

if(a > k):
  max += k
  k = 0
else:
  max += a
  k -= a 
  
if(k != 0)and(b > k):
  k = 0
elif k != 0:
  k -= b
  
if(c > k):
  max -= k
elif k != 0:
  max -= c

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x=0

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

Submission status: Accepted

Solution code:
#--Easy Linear Programming

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

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

if (k > a):
    number = number + a
    count = count + a

kk = k - number

if (kk <= b):
    print(count)
    exit()

if (kk > b):
    number = number + b

kkk = k - number

if (kkk <= c):
    count = count - kkk
    print(count)
    exit()

if (kkk > c):
    count = count - c

print(count)