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

Submission status: Accepted

Solution code:
def main():
  a,b,c,k = [int(x) for x in input().split()]
  out = 0
  
  for (num, count) in zip([1, 0, -1], [a, b, c]):
    if k <= 0:
      break
    pick = min(k, count)
    k -= pick
    out += (num*pick)
  print(out)
main()

Submission status: Accepted

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

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:
import sys
from collections import deque
import copy
def main():
    a, b, c, K = map(int, input().split())
    ans = 0
    ans += min(K, a)
    K -= a
    if K > 0:
        K -= b
    if K > 0:
        ans -= K
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,c,k = input().split(None, 4)
A = int(a)
B = int(b)
C = int(c)
K = int(k)
X = K - A - B
if K <= A:
    print(K)
elif A < K <= A + B:
    print(A)
else:
    print(A - X)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

s = 0
if k <= a+b:
    s = min(k, a)
else:
    s = a - (k-a-b)

print(s)

Submission status: Accepted

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

if card[3] <= card[0]:
  result = card[3]
elif card[0] < card[3] and card[3] <= card[1]:
  result = card[0]
else:
  result = card[0] - (card[3] - (card[0] + card[1]))

print(result)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, k = map(int, 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 = list(map(int, input().split()))

c = k- a- b

if c < 0 :
    c = 0
if a > k:
    a = k


print(a -c)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

l = A + B + C - K

def solve(A, B, C, K):
    result = 0
    n = min(A, K)
    result += n
    K -= n
    A -= n
    if K == 0:
        return result
    n = min(B, K)
    K -= n
    B -= n
    if K == 0:
        return result
    n = min(C, K)
    result -= n
    K -= n
    C -= n
    return result

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

Submission status: Accepted

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

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

res = 0
d = min(a, k)
k -= d
res += d
d = min(b, k)
k -= d
d = min(c, k)
res -= d
print(res)

Submission status: Accepted

Solution code:
a, b, c, k = [int(tmp) for tmp 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:
def main():
    A,B,C,K=map(int,input().split())
    print(min(A, K) - max(0, K-A-B))
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    A,B,_,K=map(int,input().split())
    print(min(A, K) - max(0, K-A-B))
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    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))
    return

if __name__=='__main__':
    main()

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

Submission status: Accepted

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

ak = min(a, k)
k -= ak
if k == 0:
    ans = ak
    print (ans)
else:
    bk = min(b, k)
    k -= bk
    if k == 0:
        ans = ak
        print (ans)
    else:
        ck = k
        ans = ak- ck
        print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

def main():
    mod=10**9+7
    a,b,c,k=MI()
    ans=0
    if a>=k:
        ans=k
    else:
        ans=a
        k-=a
        if b>=k:
            pass
        else:
            k-=b
            ans-=k
            
    print(ans)

main()

Submission status: Accepted

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

ans=0
n=k

x=min(a,n)
ans+=x
n-=x

y=min(b,n)
n-=y

z=min(c,n)*-1
ans+=z

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:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
A,B,C,K = inputlist()
if A >= K:
    print(K)
    exit()
if A +B >= K:
    print(A)
    exit()
print(2*A-K+B)

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

A, B, C, K = inpl()
if A >= K:
    print(K)
    exit()
if A+B >= K:
    print(A)
    exit()

print(A - (K-A-B))

Submission status: Accepted

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

Submission status: Accepted

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

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

    ans -= k
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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:
from sys import stdin
A, B, C, K = [int(_) for _ in stdin.readline().rstrip().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())

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

Submission status: Accepted

Solution code:
INPUT = input()
A = ''
B = ''
C = ''
K = ''
count = 0

for i in range(len(INPUT)):
    if count == 0:
        if not INPUT[i] == ' ':
            A += str(INPUT[i])
        else:
            count += 1
    elif count == 1:
        if not INPUT[i] == ' ':
            B += str(INPUT[i])
        else:
            count += 1
    elif count == 2:
        if not INPUT[i] == ' ':
            C += str(INPUT[i])
        else:
            count += 1
    elif count == 3:
            K += str(INPUT[i])

A = int(A)
B = int(B)
C = int(C)
K = int(K)
answer = 0

# 以上入力

if A >= K:
    answer = K
else:
    answer = A
    K = K - A
    if B >= K:
        pass
    else:
        K = K - B
        answer = answer - K

print(answer)

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

ans = 0
ans += min(a, k)
k -= a
k -= b
ans -= max( k, 0)

print(ans)

Submission status: Accepted

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

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

total = 0

if k > a:
    k = k-a
    total += a

elif k == a:
    k = 0
    total = a

elif k < a:
    total = k
    k = 0

if k > b:
    k = k-b

elif k == b:
    k = 0

elif k < b:
    k = 0

if k > c:
    total -= c
    k -= c

elif k == c:
    total -= k
    k = 0

elif k < c:
    total -= k
    k = 0
    
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if k<=a+b:
  print(min(a, k))
else:
  print(2*a+b-k)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
ls = list(map(int, input().split()))
nokori = ls[-1]
nokori_ = ls[-1]
sum_max = 0
for i, j in zip(ls[:-1], [1, 0, -1]):
    nokori -= i
    if nokori > 0:
        sum_max += i*j
    elif nokori == 0:
        sum_max += i*j
        break
    else:
        sum_max += nokori_*j
        break
    nokori_ = nokori
print(sum_max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def isInt(x):
    try:
        float(x)
    except ValueError:
        return False
    else:
        return float(x).is_integer()
    
def main():
    try:
        str = input().split()
    except ValueError:
        return

    ##is int?
    if isInt(str[0]):
        a = int(str[0])
    else:
        return
    if isInt(str[1]):
        b = int(str[1])
    else:
        return
    if isInt(str[2]):
        c = int(str[2])
    else:
        return
    if isInt(str[3]):
        k = int(str[3])
    else:
        return

    ## a, b, c >= 0
    if not(a >= 0 and b >= 0 and c >=0):
        return

    ## 1 <= k <= a+b+c <= 2 * 10 ** 9
    if not(1 <= k and k <= a+b+c and a+b+c <= 2 * 10 ** 9):
        return

    sum = None
    if(k <= a):
        sum = k
        return sum
    else:
        sum = a
        k -= a

    if(k <= b):
        return sum
    else:
        k -= b
        sum -= k
        return sum
        
if __name__ == '__main__':
    sum = main()
    if(isInt(sum)):
        print(sum)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

print(sum)

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

def k(n, m):
    global ans, K
    if K >= n:
        K -= n
        ans += (n * m)
    else:
        ans += (K * m)
        K = 0
        
k(A, 1)
k(B, 0)
k(C, -1)

print(ans)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=list(map(int,input().split()))
s=0
k=n[3]
a=n[0]
b=n[1]
d=k-a

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

Submission status: Accepted

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

Submission status: Accepted

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

a = min(A, K)
K -= a
b= min(B, K)
K -= b
c = min(C, K)
print(a - c)

Submission status: Accepted

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

if k>=a:
    aa=a
    k=k-a;
    if k>=b:
        bb=b
        k=k-b
        cc=k
    else:
        bb=k
        k=0
else:
    aa=k
    k=0

print(aa-cc)

Submission status: Accepted

Solution code:
a,b,c,k = [int(x) for x in 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:
i = input().split()

a = i[0]
b = i[1]
c = i[2]
d = i[3]

if int(d) <= int(a):
  print(int(d))
elif int(d) - int(a) <= int(b):
    print(int(a))
else:
  print(int(a) - (int(d) - int(a) -int(b)))

Submission status: Accepted

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

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

Submission status: Accepted

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


def main():
    import sys
    input = sys.stdin.readline

    a, b, c, k = map(int, input().split())
    ans = 0
    ans += min(a, k)

    k -= a

    if k > 0:
        k -= b

    if k > 0:
        ans -= k

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans=0

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

k-=a

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

k-=b
print(a-k)

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

cards = k
sum = 0

while (True):
    if cards > a:
        sum += a
        cards -= a
        if cards > b:
            sum += 0
            cards -= b
            if cards > c:
                sum -= c
                cards -= b
            else:
                sum -= cards
                print(sum)
                break
        else:
            print(sum)
            break

    else:
        sum += cards
        print(sum)
        break

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 = map(int,input().split())

ans = k if k<=a else a if k<=a+b else a - (k-a-b)
print(ans)

Submission status: Accepted

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

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    A, B, C, K = map(int, input().split())
    score = min(K, A) * 1
    K -= A + B
    if K > 0:
        score -= K
    print(score)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
def main():
    a,b,c,k=map(int,input().split())
    if k<=a:
        print(k)
        return
    if k<=a+b:
        print(a)
        return
    print(a-(k-a-b))

main()

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 math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()

arg = list(map(int, input().split())) # 1行, 配列

A = arg[0]
B = arg[1]
C = arg[2]
K = arg[3]

X = 0

if K <= A:
  print(K)
else:
  if 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 = min(A, K) - min(max(K - A - B, 0), C)
print(ans)

Submission status: Accepted

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

def solve(A,B,C,K):
    remain=K
    answer=0
    answer+=1*min(remain,A)
    remain-=A
    if remain<=0:
        return answer
    remain-=B
    if remain<=0:
        return answer
    answer-=remain
    return answer

out=solve(A,B,C,K)
print(out)

Submission status: Accepted

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

ans = 0

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

ans += min(b,k) * 0
k -= min(b,k)

ans += min(c,k) * -1
k -= min(c,k) #これはなくてもよい

print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = map(int,input().split())
a = min(A,K)
K -= a
b = min(B,K)
K -= b
c = min(C,K)
K -= c

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

Submission status: Accepted

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

summ = 0

if k <= a:
    summ = k

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

print(summ)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if K >= A:
    result = A
    K -= A
else:
    result = K
    K = 0

if K >= B:
    K -= B

if K > 0:
    result -=K
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k=(int(x) for x in input().split())
xa=min(a,k)
k-=xa
xb=min(b,k)
k-=xb
xc=k
ans=xa-xc
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
import bisect as bi
import heapq 

'''
#------------------PYPY FAst I/o--------------------------------#
 
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
'''
#------------------Sublime--------------------------------------#
 
#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))



def main():
    try:
        a,b,c,d=In()
        if a>=d:
            print(d)
        elif a+b>=(d):
            print(a)
        elif a+b+c>=d:
            a-=(d-b-a)
            print(a)
        else:
            print(a-c)
    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    for _ in range(1):
        main()

Submission status: Accepted

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

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

Submission status: Accepted

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

    if K<=A:
        cal=K
        print(cal)
        return

    cal+=A
    K-=A
    if K<=B:
        print(cal)
        return

    K-=B
    print(cal-K)
    return


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
inp = list(map(int,input().split()))
res = 0

if inp[3] <= inp[0] :
    res = inp[3]
elif inp[3] <= (inp[0] + inp[1]) :
    res = inp[0]
elif inp[3] < (inp[0] + inp[1] + inp[2]) :
    res = inp[0] - (inp[3] - inp[0] - inp[1])
elif inp[3] == (inp[0] + inp[1] + inp[2]) :
    res = inp[0] - inp[2] 

print(res)

Submission status: Accepted

Solution code:
def linear_program(A, B, K):
    if K <= A:
        return K
    elif K <= A+B:
        return A
    else:
        K -= A+B
        return A-K

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

Submission status: Accepted

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

x_a = min(A,K)
K -= x_a

x_b = min(B,K)
K -= x_b

x_c = min(C,K)
K -= x_c

print(x_a - x_c)

Submission status: Accepted

Solution code:
import sys

a = list(map(int,input().split()))

if a[3] > a[0]:
    b = a[0]
    a[3] = a[3]-a[0]
elif a[3] <= a[0]:
    b = a[3]
    print(b)
    sys.exit()

if a[3] > a[1]:
    a[3] = a[3] - a[1]
elif a[3] <= a[1]:
    print(b)
    sys.exit()
c = (-1) * a[3]
b = c + b
print(b)

Submission status: Accepted

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

ans = min(A, K)
K -= min(A, K)
K -= min(B, K)
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:
    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)
elif k<=a+b+c:
    print(2*a+b-k)
else:
    print(a-c)

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
ans=min(a,k)
k-=(a+b)
ans-=max(k,0)
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) 
    
#rest = K - A - B    
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

if (K- A -B) <= C:
  print(A - (K - A -B))
  exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# B
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())
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 k <= a:
  print(k)
elif k <= a + b:
  print(a)
else:
  print(2*a+b-k)

Submission status: Accepted

Solution code:
import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
a,b,c,k=map(int,stdin.readline().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())
S = 0
if K - A > 0:
    S += A * 1
    K = K - A
else:
    S += K * 1
    K = 0

if K - B > 0:
    S += B * 0
    K = K - B
else:
    S += K * 0
    K = 0

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

print(S)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
#read=sys.stdin.buffer.read
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

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

Submission status: Accepted

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