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

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    a,b,c,k=map(int,readline().split())
    if a+b>=k:
        print(min(a,k))
    elif a+b<k:
        n=k-(a+b)
        print(a-n)
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def main():
	[A,B,C,K] = list(map(int, input().split()))
	if K >= A:
		K = K - A
		ans = A
	else:
		ans = K
		return ans

	if K >= B:
		K = K - B
	else:
		ans = A
		return ans

	if K > C:
		return "NG"
	else:
		return ans - K


     
if __name__ == '__main__':
	print(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(2*a + b - 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:
  d = K - A - B
  print(A-d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#入力
input_line = input()
input_line = input_line.split(" ")
A = int(input_line[0])
B = int(input_line[1])
C = int(input_line[2])
K = int(input_line[3])

#最大値
M = 0

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

#出力
print(M)

Submission status: Accepted

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

cnt = 0

if K >= A:
    K = K - A
    cnt += A
else:
    cnt = K
    K = -1

if K > 0:
    K = K - B
if K > 0:
    cnt -= K
        
print(cnt)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K = map(int, input().split())
ans =0
for c,i in enumerate([A,B, C]):
  K -= i
  if K>=0:
    if c ==0:
    	ans += i
    elif c == 2:
      	ans -= i
      
  else:
    if c ==0:
    	ans += K +i
    elif c == 2:
      	ans -= K+i
    break
    
  

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

if B >= (K-A):
    print(A)
    sys.exit()

wa = A
sa = K-A-B
print(wa-sa)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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:
# from collections import defaultdict

# N, K = [int(i) for i in input().split()]
# A = [int(i) for i in input().split()]

# d = defaultdict(lambda: -1)
# d[1] = 0
# L = [1]
# i = 0
# k = i
# while i<N:
#     if d[A[k]]==-1:
#         d[A[k]] = i+1
#         L.append(A[k])
#         k = A[k]-1
#     else:
#         p = d[A[k]]
#         q = i+1
#         break
#     i += 1

# L = L[p:]
# print(L[(K-p)%(q-p)])

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

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

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

if (C >= K):
    print(res-K)
    quit()

Submission status: Accepted

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

if card[3] > card[0] + card[1]:
    x = card[3] - card[0] - card[1]
    print(card[0] + x * -1)
else:
    if card[0] <= card[3]:
        print(card[0])
    else:
        print(card[3])

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

Submission status: Accepted

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:

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

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

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

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

print(ans)

Submission status: Accepted

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

total=0
total+=a

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0

import sys
if a < k:
  sum = 1 * a
  k = k - a
else:
  print(1 * k)
  sys.exit()
  
if b < k:
  k = k - b
else:
  print(sum)
  sys.exit()
  
print(sum - k)

Submission status: Accepted

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

if K >= A:
    ans += 1*A
    K -= A
else:
    print(K)
    exit()

if K >= 0:
    ans += K*(B*0)
    K -= B

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

if 0 >= 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(a-(k-(a+b)))

Submission status: Accepted

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

sum = 0

if K - A > 0:
    sum += A
    K -= A
    if K - B > 0:
        K -= B
        if K - C > 0:
            sum = sum - C
        else:
            sum = sum - K
    else:
        pass
else:
    sum += K

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    a,b,c,k = inpm()
    ans = 0
    ans += min(a,k)
    ans -= max(0,k-a-b)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

sum1 = 0
sum2 = 0
sum3 = 0

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

print(sum)

Submission status: Accepted

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

while limit > 0:
    #カードの枚数が選ぶ枚数以上の場合
    if 0 < A and limit <= A:
        count += 1 * limit
        limit = 0
        A -= limit
        break
    #カードの枚数が選ぶ枚数未満の場合
    elif 0 < A:
        count += 1 * A
        limit -= A
        A = 0
    
    if 0 < B and limit <= B:
        count += 0 * limit
        limit = 0
        B -= limit
        break
    elif 0 < B:
        count += 0 * B
        limit -= B
        B = 0
    
    if 0 < C and limit <= C:
        count += -1 * limit
        limit = 0
        C -= limit
        break
    elif 0 < C:
        count += -1 * C
        limit -= C
        C = 0

print(count)

Submission status: Accepted

Solution code:
ans = 0
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())
a=0
c=0
if A<=K:
    a=A
if A>K:
    a=K
if K-A-B>0:
    if C<=K-A-B:
        c=C*-1
    if C>K-A-B:
        c=(K-A-B)*-1
print(a+c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list=list(map(int, input().split()))
A=list[0]
B=list[1]
C=list[2]
K=list[3]
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())

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# sys.exit()
a,b,c,k = map(int, input().split())
# sum = 0
if k <= a:
    sum = k
    print(sum)
    sys.exit()
else:
    sum = a
    k = k - a
if k <= b:
    print(sum)
    sys.exit()
else:
    k = k - b
    sum = sum - k
    print(sum)

Submission status: Accepted

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

def abc(A,B,C,K):
    result = 0
    #A分引く
    K = K - A
    result = A + result
    if K < 0:
        K = K + A
        result -= abs(abs(K)-A)
        return result
    K -= B
    if K < 0:
        return result
    K -= C
    result -= C
    if K < 0:
        K += C
        result += abs(abs(K)-C)
    return result
print(abc(A,B,C,K))

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
import sys
while K > 0:
    if A and A >= K:
        ans += K
        break
    elif A and A < K:
        ans += A
        K -= A
        A = 0
    elif B and B >= K:
        break
    elif B and B < K:
        K -= B
        B = 0
    elif C and C >= K:
        ans -= K
        break
    elif C and C < K:
        ans -= C
        break
print(ans)

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, k = map(int, readline().split())
if a + b >= k:
    print(min(a, k))
else:
    print(a - (k - a - b))

Submission status: Accepted

Solution code:
A,B,C,K=list(map(int,input().split()))
nokori=K
maisu1=0
maisu2=0
maisu3=0
while True:
    if A<=nokori:
        maisu1=A
        nokori=nokori-maisu1
    else:
        maisu1=nokori
        break

    if B<=nokori:
        maisu2=B
        nokori=nokori-maisu2
    else:
        maisu2=nokori
        break
    
    maisu3=nokori
    break

print(maisu1-maisu3)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
num = []
ans = 0
if(K>0):
    ans += 1*min(A,K)
    K -= A
if(K>0):
    K -= B
if(K>0):
    ans += -1*min(C,K)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if k <= a:
    ans = k
else:
    ans = a
    k = k - a
    # print("a")
    if k >= b:
        k = k - b
        ans += k * (-1)
print(ans)

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

Submission status: Accepted

Solution code:
from sys import stdin

A, B, C, K = map(int, stdin.readline().rstrip().split())
res = int(0)

def f(p, n, k, res):
    if (k - n) >= 0:
        return k - n, p * n + res
    else:
        return 0, p * k + res


K, res = f(1, A, K, res)
K, res = f(0, B, K, res)
_, res = f(-1, C, K, res)
print(res)

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 = (int(i) for i in input().split())

sum = 0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    else:
        l = k - (a + b)
        print(a - l)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    a,b,c,k = I2()
    l = k-a-b
    #print(l)
    if k <= a:print(k)
    elif a+b >= k:print(a)
    elif l <= c:print(a-l)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

Solution code:
a, b, c, k = input().strip().split()
a, b, c, k = [int(a), int(b),int(c), int(k)]
total = 0
k2 = 0
if a > k:
  total = k
else:
  k2 = k-a
  total = a
if k2 > 0:
  if b > k2:
    k2 = 0
  else:
    k2 = k2 - b
if k2 > 0:
  if c > k2:
    total = total +(k2 * -1)
  else:
    total = total +(c * -1)
print(total)

Submission status: Accepted

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

ans = 0
if a < k:
    ans = a
else:
    ans = k

minus = k - (a + b)

if minus > 0:
    ans -= minus

print(ans)

Submission status: Accepted

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

print(min(a,k)-max(0,k-a-b))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

sum_mux = 0

least_A, least_B, least_C = A, B, C
least_K = K

while 0 !=  least_K:
    if 0 != least_A:
        if least_K >= least_A:
            sum_mux += least_A
            least_K -= least_A
            least_A = 0
        else :
            sum_mux += least_K
            least_A -= least_K
            least_K = 0
    elif 0 != least_B:
        if least_K >= least_B:
            sum_mux += 0
            least_K -= least_B
            least_B = 0
        else :
            sum_mux += 0
            least_B -=least_K
            least_K = 0
    else:
        if least_K >= least_C:
            sum_mux -= least_C
            least_K -= least_C
            least_C = 0
        else :
            sum_mux -= least_K
            least_C -=least_K
            least_K = 0

print(sum_mux, flush=True)

Submission status: Accepted

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

Submission status: Accepted

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

d={}

d[1]=a
d[0]=b
d[-1]=c

ans = 0
cnt=0

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

cnt+=b
if cnt>k:
    print(ans)
    exit(0)

cnt+=c
ans-=c
if cnt>k:
    ans+=(cnt-k)
    print(ans)
    exit(0)

if cnt==k:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

output = 0

while True:
    if K == 0:
        break
    if A > 0:
        if K >= A:
            output = 1*A
            K -= A
            A = 0
            continue
        else:
            output = 1*K
            break
    if B > 0:
        if K >= B:
            K -= B
            B = 0
            continue
        else:
            break
    output -= 1*K
    K = 0

print(output)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

if c > 0:
    ans = max(ans - k, -k)

print(ans)

Submission status: Accepted

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

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

if C >= 1 and K >= 1:
    if K - C >= 0:
        sum -= C
        K -= C
    else:
        sum -= K
        K = 0

print(sum)

Submission status: Accepted

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

Atoru = min(A,K)
Btoru = max(0,min(B,K-A))
Ctoru = max(0,K-A-B)

print(Atoru-Ctoru)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    A, B, C, K = map(int, input().split())
    rest = K
    ans = 0
    ans += min(A, rest)
    if K > A:
        rest -= A
        if rest > B:
            rest -= B
            ans -= min(rest, C)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

k -= b

if k <=0:
  print(n_sum)
  sys.exit()
  
if c >= k:
  n_sum -= k
  print(n_sum)
  sys.exit()
else:
  n_sum -= c
  print(n_sum)
  sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A = input().split(" ")
sum=0
for i in range(len(A)):
    A[i]=int(A[i])
for i in range(len(A)-1):
    if A[len(A)-1] >= A[i]:
        sum+=(len(A)-3-i)*A[i]
        A[len(A)-1]= A[len(A)-1]-A[i]
    elif A[len(A)-1] < A[i]:
        sum+=(len(A)-3-i)*A[len(A)-1]
        A[len(A)-1]=0
print(sum)

Submission status: Accepted

Solution code:
a, b, c, k = [int(x) for x in input().split()]
 
if k <= a:
  print(k)
elif a < k and k<= a+b:
  print(a)
else:
  print(a-(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)
else:
    print(A - (K - (A + B)))

Submission status: Accepted

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

tot=0
all=K

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
plus, zero, minus, number = map(int, input().split(" "))

if(plus > number):
  print(number)
elif(plus + zero >= number):
  print(plus)
else:
  print(plus - number + plus + zero)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
lst = []
sum = 0
if A <= K:
    sum += 1 * A
else:
    sum += 1 * K

k = K - (A + B)

if (C <= k) and (k > 0):
    sum += -1 * C
elif (C > k) and k > 0:
    sum += -1 * k

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a,b,c,k = iim()
if k < a:
    print(k)
elif k <= a+b:
    print(a)
else:
    print(a+(k-a-b)*(-1))

Submission status: Accepted

Solution code:
#!/usr/bin/python3

#標準出力からの読み込み

input_1 = input()
a = int(input_1.split(" ")[0])
b = int(input_1.split(" ")[1])
c = int(input_1.split(" ")[2])
k = int(input_1.split(" ")[3])

max_value = 0

if k <= a:
    max_value = k
elif k <= b:
    max_value = a
else:
    max_value = a - (k - a - b)

print(max_value)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

A, B, C, K = read_ints()

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

Submission status: Accepted

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

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



if B >= bullet:
    print(score)
    exit()
else:
    bullet -= B
    pass
  
if C >= bullet:
    print(score - bullet)
    exit()
else:
    exit()

Submission status: Accepted

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

if a <= k:
    if b <= (k-a) :
        total = a - (k-a-b)
    else:
        total = k
else:
    total = k

print(total)

Submission status: Accepted

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

Submission status: Accepted

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