Problem:


Score : 200 points

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

0 \leq A, B, C

1 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with 1s and one card with a 0.
In this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000



Sample input:
2 1 1 3


Sample output:
2

Submission status: Accepted

Solution code:

import math

def input_num():
	ls = input().strip().split(" ")
	return [int(e) for e in ls]

a,b,c,k = input_num()

b_n, c_n = 0,0
a_n = min(k,a)
k -= a_n
if k > 0:
	b_n = min(k,b)
	k -= b_n
	if k > 0:
		c_n = k
print(a_n-c_n)

Submission status: Accepted

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

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

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

ans = 0

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

Submission status: Accepted

Solution code:
def main():
    from sys import stdin
    a,b,c,k = map(int,stdin.readline().rstrip().split())
    if k <=a:
        print(k)
    elif k<=a+b:
        print(a)
    else:
        print(a-(k-a-b))
main()

Submission status: Accepted

Solution code:
import sys

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

""" Input
S = input().rstrip()
N = int(input())
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

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

total = 0
if K >= A:
    total += 1 * A
    K -= A
    if K >= B:
        total += 0 * B
        K -= B
        if K >= C:
            total += (-1) * C
        else:
            total += (-1) * K
    else:
        pass

else:
    total = K * 1

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

ans += min(a, k)
k -= a
k -= b
if k <= 0:
    print(ans)
    exit()
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())
# A 1が書かれている
# B 0が書かれている
# C -1が書かれている
# K 枚選ぶ
if K <= A:
    print(K)
elif K <= A+B:
    print(A)
else:
    minus = K-A-B
    print(A-minus)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
if a >= k:
    ans += k
else:
    ans += a
    k -= a
    k -= b
    if k > 0:
        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 = 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:
#import math
#=input()
#=int(input())
a,b,c,k=map(int,input().split())
#=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

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

Submission status: Accepted

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc167/abc167_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A, B, C, K = i2nn()
    if K < A:
        print(K)
    elif K <= A + B:
        print(A)
    else:
        print(A - (K - (A + B)))
    return

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect

def solve(a, b, c, k):
    if k < a:
        return k
    if k < a + b:
        return a
    get_c = k - (a + b)
    return a - get_c

if __name__ == '__main__':
    a, b, c, k = list(map(int, input().split()))
    ans = solve(a, b, c, k)
    #print('ans') # debug
    print(ans)

    #print('\33[32m' + 'end' + '\033[0m') # debug

Submission status: Accepted

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


print(main())

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
ans = 0
take = min(a, k)
k -= take
ans += take
take = min(b, k)
k -= take
take = min(c, k)
ans -= take
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-B-A)*(-1))

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

Submission status: Accepted

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

    ans = 0
    if k <= a:
        return k
    
    ans += a
    k -= a
    if k <= b:
        return ans
    
    k -= b
    return ans - k


print(submit())

Submission status: Accepted

Solution code:
import sys

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

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

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

    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b, c, k = na()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def solve():
    A, B, C, K = map(int,input().split())
    if A>K:
        return K
    K-=A
    if B>K:
        return A
    K-=B
    A-=K
    return A

print(solve())

Submission status: Accepted

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

total = 0

first = min(a, k)
k -= first
total += first

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

third = min(c, k)
total -= third

print(total)

Submission status: Accepted

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

    res = K
    ans = 0
    ans += min([A, K])
    res -= min([A, K])
    if res == 0:
        print(ans)
        exit()
    res -= min([res, B])
    if res == 0:
        print(ans)
        exit()
    ans -= min([res, C])
    print(ans)


if __name__ == "__main__":
    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:
a, b, c, k = list(map(int, input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(M)

Submission status: Accepted

Solution code:
a,b,c,k=(int(i) for i in input().split())
s=0
s+=min(k,a)
k-=a
if(k>0):
  k-=b
  if(k>0):
    k1=min(k,c)
    k-=k1
    s-=k1
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(A-(K-A-B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
sys.setrecursionlimit(10**9)

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

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

Submission status: Accepted

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


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

    if B >= K:
        return result
    K -= B

    return result - K


print(solve())

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if a < k:
    k -= a
    ans += a
else:
    ans = k
    k = 0
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 A <= K:
    ans += A
else:
    ans += K
K -= A+B

if K>0:
    ans -= K

print(ans)

Submission status: Accepted

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

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

if A < K and K <= A + B:
    print(A)
    exit()

if A+B < K:
    print(A - (K - A - B))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    s = input().rstrip().split(' ')
    A, B, C, K = int(s[0]), int(s[1]), int(s[2]), int(s[3])
    score = 0
    if K <= A:
        score = K
    elif K <= A+B:
        score = A
    elif K <= A+B+C:
        score = A - (K-A-B)

    print(score)

Submission status: Accepted

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

def p(A, B, C, K):
    point = 0

    if K >= A:
        K -= A
        point += A
    else:
        point += K
        return point

    if K >= B:
        K -= B
    else:
        return point
    
    point -= K
    return point


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

Submission status: Accepted

Solution code:
a,b,c,K=map(int,input().split())
if K<=a:
    ans=K
else:
    ans=a-1*max((K-a-b),0)
print(ans)

Submission status: Accepted

Solution code:
def maxSum(a, b, c, k):
  currentSum = 0
  currentSum += min(a, k)
  k -= a
  if k <= 0:
    return currentSum
  k -= min(b, k)
  if k <=0:
    return currentSum
  currentSum -= min(c, k)
  return currentSum

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

Submission status: Accepted

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

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

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

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

print(m)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
import sys

A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if K <= A:
    print(K)
    sys.exit()
elif K <= A+B:
    print(A)
    sys.exit()
else:
    print(A-(K-A-B))
    sys.exit()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#coding: utf-8
A, B, C, K = map(int, input().split())
# li = [1 for _ in range(A)] + [0 for _ in range(B)] + [-1 for _ in range(C)]
ans = 0
li = [A, B, C]
ll = [1, 0, -1]
i = 0
while K > 0:
    if li[i] <= K:
        ans += ll[i] * li[i]
        K -= li[i]
    else:
        ans += ll[i] * K
        K = 0
    i += 1
print(ans)

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
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
    k=0
else:
    ans+=a
    k-=a

if(k<=b):
    k=0
else:
    k-=b

if(k>0):
    ans-=k
    k=0

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:
#N = int(input())
#J,K = map(int,input().split())
#A = list(map(int(input().split())))
#A = [list(map(int(input().split()))) for _ in range(N)]
#for i in range():

#N = int(input())
#J,K = map(int,input().split())
#A = list(map(int(input().split())))
#A = [list(map(int(input().split()))) for _ in range(N)]
#for i in range():

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

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

Submission status: Accepted

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

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

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 + -1 * (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(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)
else:
    AB=A+B
    if K <= AB:
        print(A)
    else:
        K2=K-A-B
        Ans=A-K2
        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))*(-1)
print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# import numpy as np
# from itertools import *
# from collections import *

# S = input()
# N = int(input())
# K, N = [int(x) for x in input().split()]

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

score = min(A, K)

K -= A

if K <= 0:
    print(score)
    exit(0)

K -= B

if K <= 0:
    print(score)
    exit(0)

score -= min(K, C)

print(score)

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

Solution code:


def solve():
    ke = k
    ans = min(a, ke)
    ke = max(0, ke - a - b)
    ans -= ke
    print(ans)
    return



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

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

Submission status: Accepted

Solution code:
list = [int(i) for i in input().split(" ")]
sum = 0
if list[0] < list[3]:
    sum = list[0]
    if list[0] + list[1] < list[3]:
        minus = list[3] - list[1] - list[0]
        sum = sum - minus
else:
    sum = list[3]
print(sum)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
import heapq
import itertools
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b,c,K = IL()

if K <= a:
  print(K)
elif a < K <= a+b:
  print(a)
else:
  print(a - (K - (a+b)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


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

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


if __name__ == '__main__':
    main()

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

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

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:
    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:
def main():
    a,b,c,k = tuple([int(t)for t in input().split()])

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

Submission status: Accepted

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

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 = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math

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)*-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
from collections import defaultdict
import collections
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

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())
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:
#!/usr/bin/env python3

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k = map(int, raw_input().split(' '))
def f(a,b,c,k):
	elems = [(a,1), (b,0), (c,-1)]
	i = 0
	res = 0
	while(k and i <len(elems)):
		res += min(k, elems[i][0]) * elems[i][1] 
		k-= min(k, elems[i][0])
		i+=1
	return res

print f(a,b,c,k)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

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

Submission status: Accepted

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


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

    if a - k  >= 0:
        return 1 * k

    if a + b - k >= 0:
        return 1 * a

    return 1 * a + (-1 * (k - a - b))


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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



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

Submission status: Accepted

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

ans=0
if A<=K:
    ans+=A
    K-=A

else:
    ans+=K
    print(ans)
    exit()

if B<=K:
    K-=B

else:
    print(ans)
    exit()

if C<=K:
    ans-=C
    print(ans)

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

Submission status: Accepted

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

if a > k:
    ans = k
elif a+b>=k:
    ans = a
elif k > a+b:
    ans = 2*a + b -k

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

Submission status: Accepted

Solution code:
# Contest No.: ABC167
# Problem No.: B
# Solver:      JEMINI
# Date:        20200510

import sys

def main():
    a, b, c, k = map(int, sys.stdin.readline().split())
    ans = 0
    if k <= a:
        print(k)
        return
    else:
        k -= a
        ans += a
    if k <= b:
        print(ans)
        return
    else:
        k -= b
        print(ans - k)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

A, B, C, K = map(int, sys.stdin.readline().strip().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())

if K <= A:
    print(K)

elif K <= A + B:
    print(A)

else:
    print(A - (K - A - B) * 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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