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:
from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math
import math
import time

def bin1(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=k**mid
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin1(mid+1,r,k,t,b,val,ans)
		else:
			return bin1(l,mid-1,k,t,b,val,ans)
		
def bin2(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=t*(k**mid)+b*(mid)
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin2(l,mid-1,k,t,b,val,ans)
		else:
			return bin2(mid+1,r,k,t,b,val,ans)

def SieveOfEratosthenes(n): 
      
    # Create a boolean array "prime[0..n]" and initialize 
    #  all entries it as true. A value in prime[i] will 
    # finally be false if i is Not a prime, else true. 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
          
        # If prime[p] is not changed, then it is a prime 
        if (prime[p] == True): 
              
            # Update all multiples of p 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    l=[]
    for i in range(2,n+1):
    	if(prime[i]):
    		l.append(i)
    return l
def bin(l,r,ll,val):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		if(val>=ll[mid][0] and val<=ll[mid][1]):
			return mid
		elif(val<ll[mid][0]):
			return bin(l,mid-1,ll,val)
		else:
			return bin(mid+1,r,ll,val)
def deci(n):
	s=""
	while(n!=0):
		if(n%2==0):
			n=n//2
			s="0"+s
		else:
			n=n//2
			s="1"+s
	return s
def diff(s1,s2):
	if(len(s1)<len(s2)):
		v=len(s1)
		while(v!=len(s2)):
			s1="0"+s1
			v=v+1
	else:
		v=len(s2)
		while(v!=len(s1)):
			s2="0"+s2
			v=v+1
	c=0
	for i in range(len(s1)):
		if(s1[i:i+1]!=s2[i:i+1]):
			c=c+1
	return c
from sys import stdin, stdout 
def fac(a,b):
	v=a
	while(a!=b):
		v*=a-1
		a=a-1
	return v
def bino(l,r,n):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		val1=math.log((n/mid)+1,2)
		val2=int(val1)
		if(val1==val2):
			return val1
		elif(val1<1.0):
			return bino(l,mid-1,n)
		else:
			return bino(mid+1,r,n)

def binary(l,r,val,ans):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		v=val**5-mid**5
		print(v)
		if(v==ans):
			print("HOHOHOH")
			return mid
		elif(v<ans):
			return binary(mid+1,r,val,ans)
		else:
			return binary(l,mid-1,val,ans)
def check(n):
	v=1
	while(n!=0):
		if(n%10==0 or n%10==1):
			n=n//10
		else:
			v=0
			break
	return v
def stairs(n,m,val,c,l):
	if(val>n):
		return 100000
	elif(val==n):
		if(l[val]!=-1):
			return l[val]
		elif(c%m==0):
			l[val]=c
			return l[val];
		else:
			l[val]=100000
			return l[val]
	else:
		# if(l[val]!=-1):
		# 	return l[val]
		# else:
		l[val]=min(stairs(n,m,val+1,c+1,l),stairs(n,m,val+2,c+1,l))
		return l[val]
def fact(n):
	if(n==0 or n==1):
		return 1
	else:
		return n*fact(n-1)

def some(n):
	s=0
	while(n!=0):
		s+=fact(n%10)
		n//=10
	return s
def bin(l,r,val,ll):
    if(l>r):
        return -1
    else:
        mid=(l+r)//2
        if(ll[mid]==val):
            return mid
        elif(ll[mid]>val):
            return bin(l,mid-1,val,ll)
        else:
            return bin(mid+1,r,val,ll)

if __name__ == '__main__':
	a,b,c,k=map(int,input().split())
	total=0
	if(a>=k):
		print(k)
	else:
		total+=a
		k-=a
		if(b>=k):
			print(total)
		else:
			k-=b
			total+=(-1)*k
			print(total)

Submission status: Accepted

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

Submission status: Accepted

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

use_A = min(A, K)

sumv += use_A
remain = K - use_A
use_B = min(B, remain)
use_C = remain - use_B
sumv += (-1* use_C)
print(sumv)

Submission status: Accepted

Solution code:
A, B, C, K = list(map(int, input().split()))
 
if (A >= K):
  print(K*1)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k = (int(x) for x in input().split())
total=0
total += min(a,k)
k -= min(a,k)
if k==0:
    print(total)
    exit()

if k>0:
    k -= min(b,k)
    if k==0:
        print(total)
        exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(Result)

Submission status: Accepted

Solution code:
A,B,C,K = map(int, input().split())
cnt=0
res=0
if A >= K:
  print(K)
  exit(0)

cnt=A
res = K-A

if B >= res:
  print(cnt)
  exit(0)
res=res-B
print(res*-1+cnt)

Submission status: Accepted

Solution code:
def j():
    a,b,c,k=map(int,input().split())
    o=0
    x=k
    if a!=0:
        o+=a
        k-=a
        if k==0:
            return a
        elif k<0:
            return x
    if b!=0:
        k-=b
        if k<=0:
            return a
    if c!=0:
        k-=c
        o-=c
        if k==0:
            return o
        elif k<0:
            return o-k
print(j())

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

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

ans -= k

print(ans)

Submission status: Accepted

Solution code:
#B

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

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

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:
from sys import stdin

a, b, c, k = [int(_) for _ in stdin.readline().rstrip().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
import sys


try:
    sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
    sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
    pass


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

    if 1 <= k <= a + b:
        return min(a, k)
    
    if k > a + b:
        diff = k - a - b
        return a - diff

print(solve())

Submission status: Accepted

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

total = 0

if a >= num:
    print(num)
    sys.exit()

total += a
num -= a

if b >= num:
    print(a)
    sys.exit()

num -= b
    
print(a-num)

Submission status: Accepted

Solution code:
#x,y = map(int,input().split())
#arr = [int(i) for i in input().split()]
from collections import Counter
import math
mod = 10**9+7

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

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

Submission status: Accepted

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

total = 0

if A >= K:
    total = K
    print(total)
    exit()
else:
    total = A
    K -= A

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

total -= K
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if k-a>=0:
  k=k-a
  count=a
  if k-b>=0:
    k=k-b
    count-=k
else:
  count=k

print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd

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


res = 0
if K <= a:
    res = K
elif K <= a+b:
    res = a
elif K <= a+b+c:
    res = a-(K-a-b)
print(res)

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

Submission status: Accepted

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

if a <= k:
    sum += a
    k -= a
else:
    sum += k
    k = 0
    
if k > 0:
    k -= b
    if c <= k:
        sum -= c
        k -= c
    else:
        sum -= k

print(sum)

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,c,k = LI()
    if k <= a+b:
        print(min(k,a))
    else:
        print(a-(k-a-b))
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
if a>=k:
    print(k)
else :
    kk = k-a%k
    A = a%k
    if b>=kk:
        print(a%k)
    else :
        kkk = kk-b%kk
        B = b%kk
        if c >= kkk:
            print(a%k-1*(k-A-B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    D -= B
    if D <= 0:
        print(A)
    else:
        print(A - D)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0
a = min(A, K)
ans += a

K -= a
b = min(B, K)
K -= b

c = min(C, K)
ans -= c

print(ans)

Submission status: Accepted

Solution code:
def resolve():
	a, b, c, k = map(int, input().split())
	s = [a, b, c]
	n = [1, 0, -1]
	ans = 0
	for i in range(3):
		if k - s[i] < 0:
			ans += n[i] * k
			print(ans)
			return
		k -= s[i]
		ans += s[i] * n[i]
	print(ans)
resolve()

Submission status: Accepted

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


if(K<=A):
    a=K
    print(a)
    exit()
else:
    a=A
    if(A+B>=K):
        print(a)
        exit()
    else:
        if(A+B+C>=K):
            print(a-(K-A-B))
            exit()
        else:
            print(a-C)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if k-a <= 0:
    print(k)

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

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

Submission status: Accepted

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

ans = 0
if 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 = (int(x) for x in input().split())

if a>=k:
  print(k)
elif a+b>=k:
  print(a if a>0 else 0)
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:
        print(a-(x-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)
elif a==0 and b==0:
    print(-1 * k)
else:
    ans = a - (k - a - b)
    print(ans)

Submission status: Accepted

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

# 合計の金額
wa = 0
# 残機
res = k


if res > 0:
    wa += min(res, a)
    res -= min(res, a)

if res > 0:
    res -= min(res, b)
    
if res > 0:
    wa -= res

print(wa)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
if A<=K:
    ans+=A
if A>K and A!=0:
    ans+=K
    
cntK-=A+B
if cntK>0:
    ans-=cntK
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

# print(min(k, a) - max(c-(k-a-b), (k-a-b)))

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

print(ans)

Submission status: Accepted

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

if __name__ == "__main__":
    A, B, C, K = MI()
    tmp = K
    result = 0
    if K > A:
        tmp -= A
        result += A
    else:
        print(K)
        exit()
    if tmp > B:
        tmp -= B
    else:
        print(result)
        exit()
    print(result - tmp)

Submission status: Accepted

Solution code:
A, B, C, K = [int(x) for x in input().split()]
print(min(K, A) - (min(K - A - B, C) if K - A - B > 0 else 0))

Submission status: Accepted

Solution code:
def point(A, B, C, K):
    S = 0
    if K <= A:
        S = K
        return S

    S = A
    K = K - A
    if K <= B:
        return S

    K = K - B
    return S - K


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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

if a + b < k:
    print(a - (k - a - b))

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,c,k = LI()
if a + b >= k:
    print(min(a,k))
else:
    print(a - (k - a - b))

Submission status: Accepted

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

if A > K:
    print(K)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    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:
    vis = k
elif a + b >= k:
    vis = a
else:
    vis= a + (-1*(k-a-b))
    
print(vis)

Submission status: Accepted

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

# A:1
# B:0
# C:-1
# K枚

def solve():
    sum = 0
    if A >= K:
        sum += K
        return sum
    else:
        sum += A

    if A + B >= K:
        return sum
    else:
        sum -= K - A - B
    
    return sum

print(solve())

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

Submission status: Accepted

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

k = K

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

Submission status: Accepted

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

output = 0

left_after_a = k - a

if left_after_a <= 0:
    output = k
else :
    output += a
    
left_after_b = left_after_a - b

if left_after_b <= 0:
    pass
else :
    left_after_c = left_after_b - c
    if left_after_c <= 0:
        output -= left_after_b
    else :
        output -= c
        
print(output)

Submission status: Accepted

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

count = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
ret = 0

cnt += a
ret += a
if(cnt > k):
  ret -= cnt-k
if(cnt < k):
  cnt += b
if(cnt < k):
  cnt += c
  ret -= c
  if(cnt > k):
    ret += cnt-k

print(ret)

Submission status: Accepted

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

solve()

Submission status: Accepted

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

Submission status: Accepted

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

print(min(A, K)-min(max(0, K-A-B), C))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = list(map(int, input().split()))

a = x[0]
b = x[1]
c = x[2]
k = x[3]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import numpy as np
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())

result = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if(K<=A):
  point=K
  print(point)
  sys.exit()
else:
  point+=A
  K-=A

if(K<=B):
  print(point)
  sys.exit()
else:
  K-=B
  point-=K
  print(point)

Submission status: Accepted

Solution code:
#from pprint import pprint
#import itertools
#from collections import deque
#
#list(map(int,input().split()))
#int(input())

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

#print(a,b,c,k)

#abc = [1]*a + [0]*b + [-1]*c
#print(abc)

result = 0

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

Submission status: Accepted

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

if a >= K:
    ans = K
    
    
elif a+b >= K :
    ans = a
    

else:
    ans = a - (K-a-b)
    

print(ans)

Submission status: Accepted

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

ans = 0
cards = [a, b, c]
nums =  [1, 0, -1]

i = 0

while k>0:
    if cards[i] <= k:
        ans += cards[i] * nums[i]
        k -= cards[i]
    else:
        ans += nums[i] * k
        break
    i += 1

print(ans)