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

if A <= K:
    temp -= A
    ans = A
else:
    temp = 0
    ans = K

if B <= temp:
    temp -= B
else:
    temp = 0

if C <= temp:
    ans -= C
else:
    ans -= temp

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

    

(A, B, C, K) = tuple([int(s) for s in input().split()])
print(calc(A, B, C, K))

Submission status: Accepted

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


def solve(A: int, B: int, C: int, K: int):
    sum = 0
    l = K - A
    if l <= 0:
        sum += K
    else:
        sum += A
    l -= B
    if l > 0:
        sum -= l
    print(sum)
        
        
    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:
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
mod = 1000000007

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

ans = 0
if k <= a:
    ans += k
else:
    ans += a
    if k - a <= b:
        pass
    else:
        ans += -1 *(k - a - b)

print(ans)

Submission status: Accepted

Solution code:
def main():
    A, B, C, K = [int(x) for x in input().split()]
    ans = 0

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def input_one_number():
    return int(input())

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

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

A,B,C,K = input_multiple_number()

ans = 0

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

Submission status: Accepted

Solution code:
import io, os
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
R = lambda : map(int, input().split())
a, b, c, k = R()
ans = min(a, k)
if a > ans or k <= a + b:
    print(ans)
else :
    print(ans - min(c, k - a - b))

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    A, B, C, K = map(int, input().split())
    if K <= A+B:
        print(min(A,K))
    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:
    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)
else:
    if k-a <= b :
        print(a)
    else:
        print(a-(k-a-b))

Submission status: Accepted

Solution code:
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

ans = 0


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

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

ans -= min(C, K)


print(ans)

Submission status: Accepted

Solution code:
#n=int(input())
a,b,c,k=map(int,input().split())
#a=list(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/python3
# -*- coding: utf-8 -*-
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:
    ans += A
    K -= A
    if B < K:
        K -= B
        ans -= K
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys 
try:
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for tt in range(1):
	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:
a,b,c,k=map(int,input().split())

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

k-=b

#print(k)

if k<0:
    print(ans)
else:
    print(ans-k)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)


def main():
    A, B, C, K = map(int, input().split())
    num = K
    if K <= A:
        print(K)
    elif (A + B) >= K:
        print(A)
    else:
        # import pdb; pdb.set_trace()
        print(2 * A + B - K)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys

def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    a,b,c,k = _ia()
    r = min(k,a)
    if k > a+b:
        r -= (k-a-b)
    return r

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count=0

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

Submission status: Accepted

Solution code:
# coding:utf-8

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

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

Submission status: Accepted

Solution code:
A, B, C, K = 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 k <= a:
    print(k)
elif a < k <= (a+b):
    print(a)
else:
    num = k-a-b
    print(a-num)

Submission status: Accepted

Solution code:
a,b,c,k = list(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)
else:
    print(2*a+b-k)

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    A, B, C, K = iim()

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

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

def main():
    a,b,c,k = readInt()
    ans = 0
    if a>k:
        print(k)
        return
    else:
        ans += a
        k -= a
    if b>k:
        print(ans)
        return
    else:
        k -= b
    if c>k:
        ans -= k
    else:
        ans -= c
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 20:59:16 2020

@author: shinba
"""
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:
# -*- coding: utf-8 -*-

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

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

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 = [int(i) for i in input().split()]
ans = min([A,K])
K -= A + B
if K < 1:
    print(ans)
    exit()
ans -= K
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
    a = min(A, K)
    b = min(B, K - a)
    c = min(C, K - a - b)
    print(a - c)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, random
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
    inf = 10 ** 20

#    t = int(input())
    # t, a, b = map(int, input().split())
    t = 1
    
    
    for _ in range(1, t+1):
        # print("Case #{}: ".format(_), end = '')
        
        a, b, c, k = map(int, input().split())
        ans = 0
        if(k):
            ans += min(k, a)
            k -= min(k, a)
        if(k):
            k -= min(k, b)
        if(k):
            ans -= k
        
        print(ans)
        
main()

Submission status: Accepted

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

Submission status: Accepted

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

total = 0

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

total = a
k = k - a

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

k = k - b
print(total - k)

Submission status: Accepted

Solution code:
# Code for B - Easy Linear Programming
# Use input() to fetch data from STDIN
[a, b, c, k] = map(int, input().split())

takeA = min(a, k)
takeB = min(b, k - takeA)
takeC = min(c, k - takeB - takeA)

print(takeA - takeC)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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())
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())
print(min(a,k)-min(max(k-a-b,0),c))

Submission status: Accepted

Solution code:
from sys import stdin
A,B,C,K = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
ans += min(K,A)
if K - A - B > 0:
    ans -= (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:
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())
if a >= k:
  print(k)
elif a + b >= k:
  print(a)
else:
  print(a - (k - a - b))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict,Counter

sys.setrecursionlimit(10**7)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    a,b,c,k=mis()
    ans=0
    if k<=a:
        ans=k
    elif 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())

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

    print(ans - K)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

A, B, C, K = LI()

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 = (int(x) for x in input().split())
ans = min(a,k)
k -= a
if k > 0:
    k -= b
if k > 0:
    ans -= min(c,k)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

A, B, C, K = In.ints()

res = 0

res += min(K, A)

K-=A

if K>0:
    K-=B

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

Out.int(res)
 
######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

summ = min(K,A) - max(K-A-B,0)
print(summ)

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

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

Submission status: Accepted

Solution code:
import math

a,b,c,k=map(int,input().split())
ans=0
xx=min(a,k)
a-=xx
k-=xx
ans+=xx 
yy=min(b,k)
b-=yy
k-=yy
zz=min(c,k)
c-=zz
k-=zz
ans-=zz
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


def main() -> None:
    A, B, C, K = rmi()
    sum_ = 0
    if A < K:
        sum_ += A
        K -= A
    else:
        sum_ += K
        K = 0
    if B < K:
        K -= B
    else:
        K = 0
    if 0 < K:
        sum_ -= K
    w(sum_)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> tuple:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(*data, delim: str = ' ') -> None:
    print(delim.join(map(str, data)))


if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10 ** 9)
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a, b, c, k = na()
ans = 0
if a >= k:
    print(k)
else:
    res = k - a
    ans += a
    if b >= res:
        print(ans)
    else:
        print(ans - (res - b))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline 


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

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

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

if a < k:
    ans = a
    k -= a
    if b < k:
        k -= b
        if c < k:
            ans -= c
        else:
            ans -= k
else:
    ans = k

print(ans)

Submission status: Accepted

Solution code:
a,b,c,k=[int(_) for _ in input().split()]
d=min(a,k)
point=d
k-=d
if k>0:
    e=min(b,k)
    k-=e
    if k>0:
        f=min(c,k)
        point-=f
print(point)

Submission status: Accepted

Solution code:
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
l = sys.stdin.readline().strip()
A, B, C, K = map(int, l.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 a>=k:
    print(1*k)
    exit()
if a+b>=k:
    print(a)
    exit()
print(a+(k-a-b)*-1)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# B - Easy Linear Programming

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

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

Submission status: Accepted

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

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)
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:
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


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


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if k <= a:
    print(k)
    sys.exit()
    
if k <= a + b:
    print(a)
    sys.exit()
    
num = k - a - b
print(a - num)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
A,B,C,K = map(int,input().split())
if K <= A:
    print(K)
elif K <= A+B:
    print(A)
elif K <= A+B+C:
    p = K - A - B
    print(A-p)
else:
    print(A-C)