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 sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    a, b, c, k = MII()
    if k <= a:
        print(k)
    elif k <= a+b:
        print(a)
    elif k <= a+b+c:
        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(int(K))
else:
  if K - A <= B:
    print(int(A))
  else:
    print(int(A + (-1)*(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 and k>a:
    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 a <= k 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(K)
elif A<K<=A+B:
    print(A)
elif A+B<K:
    print(A-(K-(A+B)))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
A,B,C,K = map(int,input().split())

num = K
ans = 0
if num - A <= 0:
    print(K)
    exit()
elif num - A - B <= 0:
    print(A)
    exit()
elif num - A -B -C <=0:
    ans = A - (K - A - B)
    print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(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:
import sys;input=lambda:sys.stdin.readline().rstrip();ints=lambda:list(map(int,input().split()))
 
def main():
    a,b,c,k = ints()
    if k<=a:
        print(k)
    elif k<=a+b:
        print(a)
    elif k<=a+b+c:
        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:
    ret = K
elif K > A and K<= B:
    ret = K
else:
    ret = A - (K-A-B)
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


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

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

Submission status: Accepted

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

card_left = k
ans += min(a, k)
card_left -= a
#print(card_left)
if(card_left >= 0):card_left -= b
if(card_left >= 0):ans -= card_left

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    a, b, c, k = ns()
    t1 = max(k - a - b, 0)
    t2 = min(k, a)

    print(-t1 + t2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

max_num = 0

is_finish = False
if A>=K:
    print(K)
else:
    max_num += A
    K -= A
    is_finish = True

if is_finish:
    if B>=K:
        print(max_num)
    else:
        print(max_num-(K-B))

Submission status: Accepted

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

def mysum(A, B, C, K):
  if K <= A:
    return(K)
  
  if K <= A+B:
    return(A)
  
  return(A + -1 * (K-A-B))
 
print(mysum(A, B, C, K))

Submission status: Accepted

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

if A>=K:
    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:
def m():
    a, b, c, k = map(int, input().split())
    ans = 0
    if (k - a) <= 0:
        return k
    k = k - a
    ans = a
    if (k - b) <= 0:
        return ans
    k = k -b
    return ans - k


print(m())

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

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

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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


ans=0

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

ans += a
k -= a

k -= b

ans -= min(c,max(0,k))

print(ans)

Submission status: Accepted

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

k2 = k-a
k3 = k2-b

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

print(ans)

Submission status: Accepted

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


def solve():
    global k

    total = 0
    num_a = min(k, a)

    total += num_a

    k -= num_a

    if k <= 0:
        return total

    num_b = min(k, b)

    if k <= 0:
        return total

    k -= num_b

    num_c = k
    total -= num_c

    return total

print(solve())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    if d - b > 0:
        d -= b
    else:
        print(ans)
        exit()

    ans -= (d)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n

a,b,c,k = readInts()
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=(int(x) for x in input().split())

a=A+B

b=K-a

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

Submission status: Accepted

Solution code:
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()

def main():
    A, B, C, K = MI()
    l = [A, B, C]; s = 0; i = 0; j = [1, 0, -1]
    while K>0:
        if K>l[i]:
            s += l[i]*j[i]
            K -= l[i]
        else:
            s += K*j[i]
            break
        i += 1
    print(s)

if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
n=input().split(' ')

for i in range(len(n)):
  n[i]=int(n[i])

k=n[3]
sum=0
if k > n[0]:
  sum+=n[0]
  k-=n[0]
else:
  sum=k
  k=0
k-=n[1]
if 0 < k:
  sum-=k
print(sum)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
A,B,C, K = (int(i) for i in input().split())
#B = [int(x) for x in stdin.readline().rstrip().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]

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

Submission status: Accepted

Solution code:
def main():

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

    print(ans)


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

A, B, C, K = IL()
maxim = 0
if A >= K:
	maxim = K
else:
	maxim = A
	K = K - A
	if B >= K:
		pass
	else:
		K = K - B
		maxim = maxim - K

print(maxim)

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

Submission status: Accepted

Solution code:
l = list(map(int, input().split(' ')))
a = l[0]
b = l[1]
c = l[2]
d = l[3]
count=0
s=0
if a>0:
    if d>=a:
        s+=a
        d-=a
    else:
        s+=d
        d-=d
if d>0:
    d-=b
if d>0:
    if d>=c:
        s-=c
        d-=c
    else:
        s-=d
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:
# coding: utf-8
# Your code here!

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

ans=0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
#n = int(input())
# n, m = list(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+b:
    print(min(a, k))
else:
    print(2*a-k+b)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = min(K,A) + min(max(0,K-A),B)*0 - min(max(K-A-B,0),C)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

A,B,C,D = map(int, input().split())
result = 0
if D-A>0:
    result +=A
    b = D-A
    if b-B > 0:
        result -=(b-B)
        print(result)
    else:
        print(result)
else:
    print(D)

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:
    k1 = abs(a + b - k)
    print(a - min(k1, c))

Submission status: Accepted

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


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

Submission status: Accepted

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

s=0
if a>=k:
    s=k
elif 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 k<=a:
    print(k)
elif a < k and 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)
else:
    k -= a
    if k <= b:
        print(a)
    else:
        k -= b
        print(a-k)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if A >= K :
    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 = map(int, input().split())
ans = min(k, a)
k -= ans
k -= min(k, b)
ans -= min(k, c)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

a,b,c,d = map(int,stdin.readline().rstrip().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

if B < K:
    K -= B
    ans -= K

print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools



#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

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

print(ans)

Submission status: Accepted

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

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("{}".format(2*A+B-K))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
num_of_cards = K

if A <= num_of_cards:
    ans += 1*A
    num_of_cards -= A
    if B <= num_of_cards:
        ans += 0
        num_of_cards -= B
        if C <= num_of_cards:
            ans += -1*C
        else:
            ans += -1*num_of_cards
    else:
        ans += 0
else:
    ans += 1*num_of_cards

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# デバッグ用
GBN_DEBUG = False
#GBN_DEBUG = True
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')

#本体ここから
a,b,c,k = map(int,input().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
A,B,C,K=map(int,input().split())
rest = K
cnt = 0
if rest > A:
  cnt += A
  rest -= A
else:
  cnt += rest
  print(cnt)
  sys.exit()
if rest > B:
  rest -= B
else:
  print(cnt)
  sys.exit()
print(cnt-rest)

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

###
# main
if(__name__ == '__main__'):
    # input
    a, b, c, k = map(int, input().split(" "))

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

        ans -= k
    else:
        ans = k

    print(ans)

# else:
    # do nothing

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

print(ans - k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
c, b, a, k = map(int, input().split())
s = min(c, k)
k -= s
if k == 0:
	print(s)
else:
	d = min(k, b)
	k -= d
	if k == 0:
		print(s)
	else:
		f = min(k, a)
		s -= f
		print(s)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- 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(a - (k - a - b))
elif a > k:
    print(k)
else:
    print(a)