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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

      ans += 0 * ( b )
      count -= b

      if count <= c:
        ans -= 1 * count
      else:
        ans -= 1 * c

      print(ans)
      return

if __name__ == "__main__":
  main()

Submission status: Accepted

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

Submission status: Accepted

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

cnt=0
left=k

#A
if a > k:
    left=0
    cnt=k
else:
    left=k-a
    cnt=a

if left>0:
    left-=b

if left>0:
    cnt-=left

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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 (A+B) < K:
    ans = A - (K-(A+B))
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:
import itertools as iter
import math as m

def main():
    X = list(map(int, input().split()))
    res = 0
    if X[3] - X[0] > 0:
        res += X[0]
        X[3] -= X[0]
    else:
        res += X[3]
        X[3] = 0

    if X[3] - X[1] > 0:
        X[3] -= X[1]
    else:
        X[3] = 0

    if X[3] - X[2] > 0:
        res -= X[2]
    else:
        res -= X[3]

    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""

from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():

    a, b, c, k = wi()
    ans = 0
    d = k - a
    e = d - b
    f = e - c
    if d >= 0:
        ans += a
        if e >= 0 and f >= 0:
            ans -= c
            print(ans)
        elif e >= 0 and f < 0:
            ans -= e
            print(ans)
        else:
            print(ans)
    else:
        ans += k
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
A, B, C, K = (int(i) for i in input().split())  
ans = 0

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

Submission status: Accepted

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


def solve(A: int, B: int, C: int, K: int):
    if K <= A:
        print(K)
    elif A < K <= A+B:
        print(A)
    elif A+B < K:
        print(A-(K-A-B))
    return


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

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

Submission status: Accepted

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

if a >= k:
    ans = k
else:
    ans = a
    k -= a
    if b >= k:
        pass
    else:
        k -= b
        if k != 0:
            ans -= k

print(ans)

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
# print(a[:-1])
count=min(a,d)
d-=a
d-=b
if d<=0:
    print(count)
else:
    print(count-d)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

a, b, c, k = map(int, input().split())
# b = [int(input()) for i in range(n)]
# c = [list(map(int, input().split())) for i in range(n)]

res = "res"


# a = 1
# b = 9
# c = 89

# k = 20

s = a if k - a >= 0 else k

action = k - a - b

if action >= 0:
  s -= action
# s += k - a
print(s)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a = raw_input().split()
for i in range(4):
    a[i] = int(a[i])
res = 0
b = [1, 0, -1]
t = a[3]
i = 0
while t:
    if a[i] < t:
        t -= a[i]
        res += a[i] * b[i]
        i += 1
    else:
        res += b[i] * t
        print res
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
A = a[0]
B = a[1]
C = a[2]
K = a[3]
if A >= K:
  print(K)
elif A<K and B>=(K-A):
  print(A)
elif B<(K-A):
  print(A+(-1)*(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(a-(k-a-b))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
"""AtCoder Beginner Contest 167: B - 
https://atcoder.jp/contests/abc167/tasks/abc167_b
"""

__author__ = 'bugttle <bugttle@gmail.com>'


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

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

    print((a * 1) + (b * 0) + (c * -1))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
if A >= K:
  ans = 1*K
elif A < 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 = map(int, input().split())
ans = 0

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

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

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

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:


import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

# 一行に文字列が一個 * n行
s_lis=[readline().rstrip().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換
# 一行に文字列が一個 * n行で文字列をアルファベット順に変換
s_lis=["".join(sorted(readline().rstrip().decode())) for _ in range(n)]
# 一行に文字列が複数個 * n行
s_lis=[readline().rstrip().split().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換

# 一行に数値が一個 * n行
s_lis=[int(readline().rstrip()) for _ in range(n)] 
# 一行に数値が複数個 * n行
s_lis=[int(readline().rstrip().split()) for _ in range(n)]

# dとAの行が交互に並んでいる場合
s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""

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

Submission status: Accepted

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

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

Submission status: Accepted

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

# print(A, B, C, K)

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

print(p)

Submission status: Accepted

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


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

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

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

if C < K:
    K -=C
    score -= C
else:
    score -= K
    print(score)
    exit()
print(score)

Submission status: Accepted

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

a_ = k - a
b_ = k - a - b

res = 0
if a_ <= 0:
    res += k
elif b_ <= 0:
    res += a 
else:
    res += a - b_

print(res)

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

ans = 0
x = k - a
if x < 0:
  ans += k
  print(ans)
  exit()
else:
  ans += a
  k = k - a


y = k - b
if y < 0:
  print(ans)
  exit()
else:
  k = k - b

z = k - c
ans -= k
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

A, B, C, K = a[0], a[1], a[2], a[3]

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys

a,b,c,k=list(map(int,input().split()))
sum=0
if(a>=k):
    print(k)
    sys.exit()
else:
    sum=a
if(b>=k-a):
    print(a)
    sys.exit()
else:
    sum=sum-(k-a-b)
    print(sum)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

print(str(ans))

Submission status: Accepted

Solution code:
import sys
stdin=sys.stdin

ns = lambda:stdin.readline().rstrip()
ni = lambda:int(stdin.readline().rstrip())
nm = lambda:map(int,stdin.readline().split())
nl = lambda:list(map(int,stdin.readline().split()))

A,B,C,K=nm()
ans=0

ans+=min(A,K)
K-=min(A,K)

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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


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 = map(int, input().split())
max_ans = 0
if K <= A:
    max_ans = K
    print(max_ans)
else:
    max_ans = A
    L = K-A #Aを除いた残りの枚数
    if L <= B:
        max_ans += L*0
        print(max_ans)
    else:
        max_ans += B*0
        M = L-B
        max_ans -= M
        print(max_ans)

Submission status: Accepted

Solution code:
import sys
a, b, c, k = [int(k) for k in input().split()]
r = 0
while k > 0:
    if k >= a:
        r += a
        k -= a
    else:
        r += k
        k -= k
        continue
    if k >= b:
        k -= b
    else:
        k -= k
    if k >= c:
        r -= c
        k -= c
    else:
        r -= k
        k -= k

print(r)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    a, b, c, k = map(int, input().split())
    ans = 0
    if k < a:
        ans = k
    elif a <= k <=  a + b:
        ans = a
    else:
        ans = a- (k - a-b)
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================

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

Max=0

if(A>=K):
    Max+=K
elif (A+B>=K):
    Max=A
else:#if (A+B+C>=K):
    Max=A-(K-A-B)

print(Max)

Submission status: Accepted

Solution code:
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0
a,b,c,k = map(int,input().split())
if k>a:
    neko = a
    if k > a + b:
        nya = a + b - k
else:
    neko = k
neko = neko + nya
print(neko)

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

a = int(temp[0])
b = int(temp[1])
c = int(temp[2])
k = int(temp[3])

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

Submission status: Accepted

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

res=0

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

print(res)

Submission status: Accepted

Solution code:
import sys
import 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 fractions import gcd
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


def main():
    A, B, C, K = MAP()
    ans = min(A, K)
    K -= A
    if K > B:
        K -= B
        print(ans - K)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if B >= K:
    print(sum)
    exit()
else:
    K = K - B

print(sum - K)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    a,b,c,k = map(int,input().strip().split())
    # print( a-max(0,k-a-b)  )
    if a>k:
        print(k)
    elif k>a+b:
        print(2*a+b-k)
    else:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K= map(int, input().split())
Anew=A
Bnew=B
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 = [int(i) for i in input().split()]

print(k if k < a+b else 2*a-k+b)

Submission status: Accepted

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

count = 0
if K > A:
    count += A
    K -= A
    if K > B:
        K -= B
        if K > 0:
            count -= K
else:
    count += K

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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