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

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

Submission status: Accepted

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

Total=()

if K<=A:
      print(K*1)
else:
      Total = A

K=K-A

if K<=B and K>0:
      print(Total)

K=K-B

if K<=C and K>0:
      Total = Total + (K*-1)
      print(Total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().split())
a=A;b=B;c=C;p=0

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

Submission status: Accepted

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

Submission status: Accepted

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

if S[0] >= S[3]:
  print(S[3])
elif S[0]+S[1] >= S[3]:
  print(S[0])
else:
  print(S[0]-(S[3]-S[0]-S[1]))

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
# 1  a枚
# 0  b枚
# -1 c枚

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

print(ans)

Submission status: Accepted

Solution code:

import sys
from collections import Counter
def main():
    a, b, c, k = map(int, input().split())
    r = 0
    if a >= k:
        print(k)
        sys.exit()
    else:
        r += a
        k -= a
    if b >= k:
        print(r)
        sys.exit()
    else:
        k -= b
    r -= min(k, c)
    print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# ans = []

# ans += [1] * a
# ans += [0] * b
# ans += [-1] * c

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

#print(sum(ans[:k]))

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    S = input().split()
    A = int(S[0])
    B = int(S[1])
    C = int(S[2])
    K = int(S[-1])

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

Submission status: Accepted

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

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

if K == 0:
    print(ans)
    exit()

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

if K == 0:
    print(ans)
    exit()


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = list(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())
sum

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

print(sum)

Submission status: Accepted

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

max = 0

if a < k:
    max = a
    k -= a
    if 0 < k:
        k -= b
        if 0 < k:
            max -= k

else:
    max = k


print(max)

Submission status: Accepted

Solution code:
val = input()
val = val.split(" ")
val = [int(i) for i in val]  # 全部intに変換

ans = 0


if(val[0] > val[3]):
    ans = 1 * val[3]
    print(ans)
elif((val[0] >= val[3]) or (val[0]+val[1] >= val[3])):
    ans = 1 * val[0]
    print(ans)
else:
    ans = 1 * val[0] - 1*(val[3]-val[0]-val[1])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_rpw_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    a, b, c, k = i_map()

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

    k -= a

    k -= b

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

    print(a-k)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

k-=a

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

if b<=k:
    k-=b
else:
    print(ans)
    sys.exit()

if c<=k:
    ans-=c
else:
    ans-=k
print(ans)

Submission status: Accepted

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

suml = 0
while k > 0:
    if a > 0:
        tmpm = min(a, k)
        a -= tmpm
        k -= tmpm
        suml += tmpm
    elif b > 0:
        tmpm = min(b, k)
        b -= tmpm
        k -= tmpm
    else:
        tmpm = min(c, k)
        c -= tmpm
        k -= tmpm
        suml -= tmpm


print(suml)

Submission status: Accepted

Solution code:
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	A, B, C, K = getlist()
	if K < A:
		print(K)
	elif A + B >= K:
		print(A)
	else:
		print(2 * A + B - K)
	




if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

goukei = 0

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

Submission status: Accepted

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

if sum_AB<=K:
    ans-=K-A-B


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

sum_value = 0
count = k

if count >= a:
    sum_value += (1 * a)
    count -= a
else:
    sum_value += (1 * count)
    count -= count
    
if count >= b:
    sum_value += (0 * b)
    count -= b
else:
    sum_value += (0 * count)
    count -= count
    
if count >= c:
    sum_value += (-1 * c)
    count -= c
else:
    sum_value += (-1 * count)
    count -= count
    
print(sum_value)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    a, b, c, k = MI()
    # print(a,b,c,k)

    aa = min(a, k)
    # print(aa)
    k -= aa
    bb = min(b, k)
    # print(bb)
    k -=bb
    cc = min(c, k)
    # print(cc)
    print(aa - 1 * cc)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

weight = [1, 0, -1]

sumAns = 0

for i in range(3):
    sumAns += lNum[i] * weight[i] if lNum[i] <= lNum[3] else lNum[3] * weight[i]
    lNum[3] -= lNum[i]
    if(lNum[3] <= 0):
        break
    
print(sumAns)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17

def check(books, x, i, m, n):
    ab = [0 for i in range(m)]
    ret = 0
    for k in range(n):
        if i % 2 == 1:
            book = books[k]
            for tab, b in enumerate(book[1:]):
                ab[tab] += b
            ret += book[0]
        i //= 2
    # print(bin(i), ab)
    for cab in ab:
        if cab < x:
            return INF

    return ret

def main():
    a,b,c,k  = getList()
    if k <= a:
        print(k)
        return

    elif k <= a + b:
        print(a)
        return

    else:
        print(a - (k - a - b))
        return
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

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

res=0

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

print(res)

Submission status: Accepted

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

d = k-a
if d == 0:
  print(a)
elif d < 0:
  print(k)
elif d > 0:
  if b >= d:
    print(a)
  else:
    i = d-b
    print(a-i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
import numpy as np

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

remainCard = K

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

Submission status: Accepted

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

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

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:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

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

ans -= (1 * K)
print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = [int(x) for x in input().split()]
if A >= K:
    print(K)
else:
    print(A - max(0, 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(2*A + B - K)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

max_num = 0

if k <= a:
    max_num = k
    print(max_num)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

number_of_A = min(A, K)
remainder = K - number_of_A

number_of_B = min(B, remainder)
remainder = remainder - number_of_B

number_of_C = remainder

total = (number_of_A * 1) + \
    (number_of_B * 0) + \
    (number_of_C * -1)

print(total)

Submission status: Accepted

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

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


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

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

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())
count=0
if a>=k:
  print(k)
else:
  n=k-a
  count=a
  if b>=n:
    print(a)
  else:
    m=n-b
    if c>=m:
      l=c-m
      p=k-a-b
      print(a-p)
    else:
      print(a-c)

Submission status: Accepted

Solution code:
import sys
A, B, C, K = map(int, 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(A-C)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if k>=a:
  tmp = k-a
  result = 1*a
else:
  result = 1*k
 
if tmp>=b:
  tmp = tmp-b

if tmp>=c:
  result += (-1)*c
else:
  result += (-1)*tmp
  
print(result)

Submission status: Accepted

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

def main(a,b,c,k):
    if(a>=k):
        return k
    k2=k-a
    if(b>=k2):
        return a
    k3=k2-b
    return a-k3
    

if __name__=='__main__':
    a,b,c,k=readinput()
    ans=main(a,b,c,k)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# print(card, K)
v = [1, 0, -1]

total = 0
for idx, c in enumerate(card):
    if K == 0:
        break
    if c <= K:
        K -= c
        total += v[idx] * c
    else:
        total += K * v[idx]
        K = 0
print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
all = input()
A = int(all.split(' ')[0])
B = int(all.split(' ')[1])
K = int(all.split(' ')[3])
if K >= A+B:
	print(A*2+B-K)
else:
	print(K)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    a, b, c, k = map(int, readline().split())
    if (0 <= k) and (k <= a):
        print(k)
    elif (a < k) and (k <= a+b):
        print(a) 
    elif (a+b < k) and (k <= a+b+c):
        print(a-(k-(a+b)))
    else:
        print(a+c)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    a, b, c, k = MI()

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(str(min(A, K) * 1 + min(B, max(K - A, 0)) * 0 + min(C, max(K - A - B, 0)) * -1))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
(a, b, c, d)=[int(x) for x in input().split()]
if a >= d:
  print(d)
elif a+b >= d:
  print(a)
elif a+b < d:
  print(a-(d-a-b))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    a, b, c, k = map(int, input().split())
    ans = 0
    if a >= k:
        print(k)
        return
    k -= a
    if b >= k:
        print(a)
        return
    k -= b
    print(a-k)


if __name__ == '__main__':
    main(sys.stdin.readline, print)

Submission status: Accepted

Solution code:
A, B, C, K = (int(x) for x in input().split())
sum = 0
if A <= K:
    sum += A
else:
    sum += K

K = K - A
K = K - B
if K >= 0:
    sum -= K

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
import math

def solve():
  a, b, c, k = map(int, input().split())
  hoge = [[a,1], [b,0], [c,-1]]
  if hoge[0][0] >= k:
    print(hoge[0][1]*k)
  elif (hoge[1][0]+hoge[0][0]) >= k:
    print(hoge[0][1]*hoge[0][0])
  else:
    print(hoge[0][1]*hoge[0][0]+(k-hoge[1][0]-hoge[0][0])*hoge[2][1])
  return 0

 
if __name__ == "__main__":
  solve()

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
lis = [a, b, c]
ans = 0
for num, i in enumerate(lis):
    if i < k:
        if num == 0:
            ans += i
        elif num == 1:
            ans += 0
        else:
            ans -= i
        k -= i
    else:
        if num == 0:
            ans += k
        elif num == 1:
            ans += 0
        else:
            ans -= k
        break

print(ans)

Submission status: Accepted

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

if b < k:
    k-=b
else:
    print(maxim)
    exit()

print(maxim-k)

Submission status: Accepted

Solution code:
def resolve():
    import sys

    input = lambda: sys.stdin.readline().rstrip()

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    A,B,C,K = LMIIS()
    
    if A >= K:
        print(K)
        return 


    if A+B >= K:
        print(A)
        return
    

    m = K-(A+B)
    print(A-m)

    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

A,B,C,K = LI()

a_value = min(A,K)
b_value = 0
c_value = 0
if K-A > 0:
    b_value = min(B,K-A)
    if K-A-B>0:
        c_value = K-A-B
ans = 1 * a_value + 0 * b_value + (-1) * c_value
print(ans)

Submission status: Accepted

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

ans = 0

if k < a:
  ans = k

elif k <= a+b:
  ans = a
else:
  ans = a - (1 * (k - a -b) )
  


print(ans)

Submission status: Accepted

Solution code:
x = [int(x) for x in input().split()]

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


if (a+b+c) == 0:
    print(0)
else:
    if (a+b) >= X:
        print(min([a,X]))
    else:
        extra = X-a-b
        print(a-extra)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
if(A >= K):
 ans = 1*K

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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