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

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

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

Submission status: Accepted

Solution code:
import math
#def main(S, b):
if __name__ == '__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))

    # if (s == t[:(len(s))] and len(t) == len(s) + 1):

    #     print("Yes")
    # else:
    #     print("No")
    # s = sum(a)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

sum=0
import sys
if K>A:
    sum+=A
    K=K-A
else:
    sum+=K
    print(sum)
    sys.exit()
if K>B:
    K=K-B
else:
    print(sum)
    sys.exit()
if K>C:
    sum-=C
    print(sum)
else:
    sum-=K
    print(sum)

Submission status: Accepted

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
A,B,C,K=map(int,input().split())
value=0
if A>=K:
    value+=K
    K=0
else:
    value+=A
    K-=A

if B>=K:
    K=0
else:
    K-=B

value-=K
print(value)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

if k > 0:
  k -= b

if k > 0:
  ans -= k

print(ans)

Submission status: Accepted

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

print(sum)

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, input().split(' '))

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

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:
abck = input().split()

a = int(abck[0])
b = int(abck[1])
c = int(abck[2])
k = int(abck[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())
ans = 0
if a >= k:
    print(k)
elif a + b >= k:
    print(a)
else:
    print(1 * a - 1 * (k - a - b))

Submission status: Accepted

Solution code:
def b():
    ones, zeros, negatives, K = map(int, input().split())
    sum = 0
    if K > ones:
        sum += ones
        K -= ones
    else:
        sum += K
        K = 0
    if K > zeros:
        K -= zeros
    else:
        K = 0
    if K > negatives:
        sum -= negatives
        K -= negatives
    else:
        sum -= K

    print(sum)


##########
if __name__ == "__main__":
    b()

Submission status: Accepted

Solution code:
a, b, c, k = list(map(int, input().split()))
def solve(a,b, c, k):
    ans = 0
    one = min(a, k)
    ans += one
    k -= one
    if k>= 0:
        zero = min(k, b)
        k -= zero
        if k >=0:
            neg_one = min(k, c)
            ans -= neg_one
    return ans
print(solve(a,b, c, k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

k-=b

if k>0:
  ans+=-1*k
  
print(ans)

Submission status: Accepted

Solution code:
# B - Easy Linear Programming

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin

def main():

    input = stdin.readline

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

    sum_num = 0
    ans_num = 0

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = min(A, K)
K -= A
if K <= 0:
    print(ans)
    sys.exit()

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

ans -= K

print(ans)

Submission status: Accepted

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

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=map(int,input().split())
if A>=K:
  print(K)
else:
  count=0
  count+=A
  if K-A<=B:
    print(count)
  else:
    count+=(K-(A+B))*(-1)
    print(count)

Submission status: Accepted

Solution code:
#abc 167
a, b, c, k = map(int, input().split())
# 1≤K≤A+B+C
if 1<= k<=  a:
    print(k)
elif a+1<= k<=  a+b:
    print(a)
elif a+b+1<= k<=  a+b+c:
    print(a-(k-a-b))

Submission status: Accepted

Solution code:
def solve(A, B, C, K):
    if K < A:
        return K
    if K < A + B:
        return A
    return A - (K - A - B)

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
def I(): return(list(map(int,input().split())))
def sieve(n):
	a=[1]*n
	for i in range(2,n):
	    if a[i]:
	        for j in range(i*i,n,i):
	            a[j]=0
	return a

a,b,c,k=I()
print(min(a-(k-(a+b)),k))

Submission status: Accepted

Solution code:
import sys
# sys.stdin = open('input.txt')


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 = [int(x) for x in input().strip().split()]
if k <= a:
  print(k)
elif k <= a + b:
  print(a)
else:
  print(a * 2 + b - k)

Submission status: Accepted

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

A = int(s[0])
B = int(s[1])
C = int(s[2])
K = int(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 k <= a:
  print(k)
elif k <= a+b:
  print(a)
else:
  print(a-(k-a-b))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    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:
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    A, B, C, K = [int(x) for x in input().strip().split()]
    if K <= A + B:
        print(min(K, 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

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

print(ans)

Submission status: Accepted

Solution code:
A,B,C,K=list(map(int,input().split()))
now = K
a = min(A,now)
now -= a
if now < 0:
    now = 0
b = min(B,now)
now -= b
if now < 0:
    now = 0
c = now
print(a-now)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


def solve(A: int, B: int, C: int, K: int):
    ans = 0
    if A <= K:
        ans += A
        K -= A
        if K > 0:
            if B <= K:
                K -= B
                if K > 0:
                    if C <= K:
                        ans -= C
                        K -= C
                    else:
                        ans -= K

    else:
        ans += K
    print(ans)

# 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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def readInt():
    return list(map(int,input().split()))

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

Submission status: Accepted

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

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

if K >= B:
    K -= B
else:
    K = 0

if K >= C:
    K -= C
    ans -= C
else:
    ans -= K
    K = 0

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    A, B, C, K = map(int, input().strip().split())
    return A, B, C, K


def solve(A, B, C, K):
    score = 0
    if K <= A:
        return K
    score = A
    K -= A
    if K <= B:
        return A
    K -= B
    return score - K


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

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

if K >= B:
    K -= B
else:
    K = 0

if K >= C:
    ans -= C
else:
    ans -= K
    K = 0
print(ans)

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



if __name__ == "__main__":
    main()

Submission status: Accepted

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

if K <= A:
    ans = K
elif A < 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 a<k<=(a+b):
 print(a)
elif (a+b)<k<(a+b+c):
 print(a-(k-a-b))
elif k==a+b+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 and K<=(A+B)):
  print(A)
elif(K>(A+B)):
  ans = A - (K-A-B)
  print(ans)

Submission status: Accepted

Solution code:
one,zero,m1,n_remain_picks = [int(s) for s in input().split()]
result = 0
if n_remain_picks <= one:
    result = n_remain_picks
    n_remain_picks = 0
else:
    result = one
    n_remain_picks -= one
    if n_remain_picks > zero:
        n_remain_picks -= zero
        result -= min(n_remain_picks, m1)
        n_remain_picks -= min(n_remain_picks, m1)

print(result)

Submission status: Accepted

Solution code:
from copy import copy, deepcopy
from collections import Counter
from math import sqrt, floor, factorial
from itertools import permutations, combinations, combinations_with_replacement
from operator import mul
from functools import reduce
import bisect

MOD = 10**9 + 7
INF = float('inf')

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

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

print(ans)

Submission status: Accepted

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

a_count = min(k, a)
score = a_count - max(0, k - a_count - b)

print(score)

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

Submission status: Accepted

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

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

if K <= A:
    print(K)
    sys.exit()
elif K <= A + B:
    print(A)
    sys.exit()
else:
    numB = K - (A + B)
    print(A - numB)
    sys.exit()

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

ans = 0

ans += min(a, k) - min(c, max(0, 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())

rlt = 0
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 = list(map(int,input().strip().split()))
ans = int(0)
if k >= a:
    ans += a
    k -= a
else:
    ans += k
    k = 0
if k >= b:
    k -= b
if k >= c:
    ans -= c
else:
    ans -= k
print(ans)

Submission status: Accepted

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

ans=0

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

if K>A+B:
    ans-=(K-A-B)

print(ans)

Submission status: Accepted

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

    if A >= K:
        V += K
        K = 0
    else:
        V += A
        K -= A

    if B >= K:
        K = 0
    else:
        K -= B

    if C >= K:
        V -= K
        K = 0
    else:
        V -= C
        K -= C

    print(V)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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


if A >= K:
  print(K)
else:
  if (K-A) <= B:
    print(A)
  else:
    print(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:
    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
else:
  s=A
  if A+B < K:
    s-=(K-A-B)
print(s)

Submission status: Accepted

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

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

K = K - A
ans = A

if B >= K:
    print(ans)
    exit()

K = K - B
print(ans-K)

Submission status: Accepted

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

    Kk = K - A
    vc = 0
    vb = 0
    if Kk > 0 :
        Kkk = Kk - B
        if Kkk > 0 :
            vc = (-1) * Kkk
        vb = 0
        print(A + vc)
    else :
        print(K)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, C, K = 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())
num = (1, 0, -1)
ans = 0
for n, m in zip(num, (a,b,c)):
  if m >= k:
    ans += k*n
    break
  else:
    ans += m*n
    k -= m
print(ans)

Submission status: Accepted

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

N = K - (A+B)

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

Submission status: Accepted

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

import sys
sys.setrecursionlimit(300000)


def solve(A: int, B: int, C: int, K: int):
    ret = 0
    ret += min(A, K)
    K = max(K - A, 0)
    if K > 0:
        K = max(K - B, 0)
        if K > 0:
            ret -= K
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, K = MAP()

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#S=input()
#T=input()
A,B,C,K=map(int,input().split(" "))
# a=[int(_) for _ in input().split(" ")]

#print("-----")

ans=0

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


print(ans)

Submission status: Accepted

Solution code:
s = input()
temp = [int(comp) for comp in s.split()]
[a, b, c, k] = temp
val = [1, 0, -1]
ans = 0
for i in range(3):
    memo = min(temp[i], k)
    ans += val[i] * memo
    k -= memo
    if (k <= 0):
        break
print(ans)

Submission status: Accepted

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


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

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

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:
#N=int(input())
A,B,C,K = map(int,input().split())
#N=int(input())
#H = list(map(int,input().split()))
#S=str(input())
c=0
if K<=A:
    print(K)
elif K <= A+B:
    print(A)
elif K <= A+B+C:
    non=A+B+C-K
    min=C-non
    print(A-min)

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()))
k = K
t = 0

t += min(k, A)
k -= min(k, A)


if k > 0 and B > 0:
    k -= min(k, B)

if k > 0 and C > 0:
    t -= min(k, C)
    k -= min(k, C)

ans = t
print(ans)

Submission status: Accepted

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

ans=0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if a < count:
    a_n = a
else:
    a_n = count    
count -= a_n

if b < count:
    b_n = b
else:
    b_n = count
count -= b_n

if c < count:
    c_n = c
else:
    c_n = count
count -= c_n

print(a_n-c_n)

Submission status: Accepted

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

#まずAを処理する。
if A >= K:
    ans += K
    A -= K
else:
    ans += A
    K -= A

if K > 0:
    if B >= K:
        print(ans)
        quit()
    else:
        K -= B

    if C >= K:
        ans -= K
        print(ans)
    else:
        ans -= C
        print(ans)

Submission status: Accepted

Solution code:
a , b, c, k = map(int,input().split())
if 0 < k < a:
    print(k)
if 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(i) for i in 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 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(2*a + b - k )

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:
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 20:50:47 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

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

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

if a <= k:
    ans += a
    k -= a

elif a > k:
    ans += k
    k -= k

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

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

print(ans)

Submission status: Accepted

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

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

    ans = 0
    k = 0
    ans += min(A, K-k)
    k += min(A, K-k)
    k += min(B, K-k)
    ans -= K-k

    print(ans)


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

Submission status: Accepted

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

Submission status: Accepted

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

n = K
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if a>=k:

    total=1*k

else:
    total+=1*a

    k=k-a-b

    if k >0:

        total+=(-1)*k


print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result=0

if A >= K:
    result = 1 * K

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

    else:
        result = (1 * A) + (0 * B) + (-1 * (K - A - B))

print(result)

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

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

print(solve())

Submission status: Accepted

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

S = 0
k = K

# A
S += 1 * min(A, k)
k = max(k - A, 0)

k = max(k - B, 0)

S -= 1 * min(C, k)

print(S)

Submission status: Accepted

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    a = kwargs["a"]
    b = kwargs["b"]
    c = kwargs["c"]
    k = kwargs["k"]

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

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["a"], kwargs["b"], kwargs["c"], kwargs["k"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

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

ans = 0
s = k - a

if s <= 0:
    print(1*k)
    exit()

ans = 1*a
s -= b

if s <= 0:
    print(ans)
    exit()

print(ans - s)

Submission status: Accepted

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