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())
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=list(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:
import sys
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
 
a,b,c,k = Mi()
if k <= a:
  print(k)
  exit(0)
ans = a
k -= a
if k > b:
  ans -= k-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:
#create date: 2020-07-03 10:10

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a, b, c, k = na()
    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:
import sys
input = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

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

A,B,C,K = list(map(int, input().rstrip().split()))
#-----

sum_num = 0

for num,cnt in [(1,A), (0,B), (-1,C)]:
    if cnt <= K:
        K -= cnt
        sum_num += num*cnt
    else:
        print( sum_num + num*K )
        sys.exit()


print(sum_num)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import exit
A, B, C, K = [int(x) for x in input().split()]

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

print(A - (K - (A + B)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def maximum():
    A,B,C,K = map(int,input().split())
    num = 0
    max = 0
    if A <= K:
        max = A
        num = K - A
        if B <= num:
            num = num - B
            max -= num
            print(max)
            return
        else:
            print(max)
            return
    else:
        print(K)
        return
maximum()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,c,k = map(int, raw_input().split())
t = [a,b,c]
s = 0
h = {0:1, 1:0, 2:-1}
for i,e in enumerate(t): 
	s += min(k, e) * h[i]
	k-= min(e,k)
print s

Submission status: Accepted

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

    if A >= K:
        print(K)
        return
    if A + B >= K:
        print(A)
        return

    print(A-(K - A - B))

    return


resolve()

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

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())
ret = min( A, K )
if A < K:
  ret -= max( 0, K - A - B )
print( ret )

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def main(a, b,c,k):

    m = 0
    if k <=a:
        m = k
    elif k <=(a+b):
        m = a
    elif k <= a+b+c:
        m = (a-(k-(a+b)))
    return m
a, b, c , k = map(int, input().split())
print(main(a,b,c,k))

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    A, B, C, K = MI()
    
    na = min(A, K)
    K -= na
    
    nb = min(B, K)
    K -= nb
    
    nc = min(C, K)
    print(na - nc)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

ans = 0
for i, j in zip([1, 0, -1], [a, b, c]):
    x = min(k, j)
    ans += i*x
    k -= x
print(ans)

Submission status: Accepted

Solution code:
#167B
#Easy Linear Programming

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
#1が書かれたカードA,0-B,-1-C,K枚選ぶ
A, B, C, K = map(int, input().split())

if A >= K:
    print(1*K)
    sys.exit()

elif A+B >= K:
    print(1*A)
    sys.exit()

else:
    print(A*1 + (K-(A+B))*(-1))
    sys.exit()

Submission status: Accepted

Solution code:
def solve(a, b, c, k):
    if k <= a:
        return 1 * k
    if k <= a+b:
        return 1 * a
    rest = k - a - b
    return (1*a) - (1*rest)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
data = stdin.readline().strip()

a = int(data.split()[0])
b = int(data.split()[1])
c = int(data.split()[2])
k = int(data.split()[3])

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())
s = 0
if a >= k:
    s = k
elif  a + b >= k:
    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:
    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())
print(min(K, A)-max(0, K-A-B))

Submission status: Accepted

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

if  a > k:
  print(k)
elif a + b >= k:
  print(a)
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(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:
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    a, b, c, k = rl()
    if a >= k:
        print (k)
    elif a + b >= k:
        print (a)
    else:
        rem = k - a - b
        print (a - rem)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

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

Submission status: Accepted

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

if(A - K < 0):
    if(A + B - K < 0):
        print(2 * A - K + B)
    else:
        print(A)
else:
    print(K)

Submission status: Accepted

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

prod = 0

if K <= A:
    prod = K
elif K > A and K <= A + B:
    prod = A 
elif K > A + B:
    prod = A - (K - (A + B))

print(prod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

a, b, c, k = map(int, sys.stdin.readline().split())
if a >= k:
  print(k)
elif a + b >= k:
  print(a)
else:
  # print(a - (k - a - b))
  print(a + a + b - k)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K=(int(x) for x in input().split())
remain_A = K-A
if remain_A<=0:
    print(K)
else:
    remain_B = remain_A - B
    if remain_B <= 0:
        print(A)
    else:
        ans = (A*1) + (B*0) + (remain_B * (-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(1*a+0*(k-a))
else :
  print(1*a+0*b+(-1)*(k-a-b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,c,k = inpl()
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:
  ans = K
elif 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())
total = 0
if A >= K:
    print(K)
    exit(0)
elif A != 0:
    K = K - A
    total = A

if B >= K:
    print(total)
    exit(0)
elif B != 0:
    K = K - B

print(total-K)

Submission status: Accepted

Solution code:
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, k = map(int, input().split())
#print(a, b, c, k)
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 A >= K:
    print(K)
else:
    print(A-(K-A-B))

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
if K<=A:
    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:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
a,b,c,k = readInts()
ans = 0
if a >= k:
    print(k)
    exit()
else: # a < k
    k -= a
    ans += a
    if b >= k:
        print(ans)
        exit()
    else: # b < k
        k -= b
        ans -= k
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if k <= a:
    print(k)
elif 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())
print(min(k,a)-max(k-a-b,0))

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
ans = False
a, b, c, k = map(int, input().split())
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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

while k > 0:
    if a <= k:
        sum += a
        k -= a
        if k <= 0:
            break
    else:
        sum += k
        break

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

    if  c <= k:
        sum -= c
        k -= c
        if k <= 0:
            break
    else:
        sum -= k
        break
    

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


ans=0

if K <= A:
  ans=K

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

Submission status: Accepted

Solution code:
import sys

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

nokori = k - a

if nokori <= 0:
    print(k)
    sys.exit()

nokori = nokori - b

if nokori <= 0:
    print(a)
    sys.exit()

print(a - nokori)

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

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())
a=min(A,K)
b=min(B,K-a)
c=min(C,K-a-b)
print(a-c)

Submission status: Accepted

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

ans = a - k

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

	else:
		ans = abs(ans)
		print(a-ans)

Submission status: Accepted

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

    while True:
        if (a < d):
            sum = a
            d -= a
        else:
            sum = d
            break

        if (b < d):
            d -= b
        else:
            break
        sum -= d
        break

    print(sum)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

if k > 0:
    ans = ans + k*(-1)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K=[int(i) for i in input().split()]
if K<A:
    P=K
else:
    P=A
    if A+B<K:
        P-=(K-(A+B))
print(P)

Submission status: Accepted

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

total = 0
for target, point in [(a,1),(b,0),(c,-1)]:
    num = min(target, k)
    k -= num
    total += point * num
    if k <= 0:
        break

print(total)

Submission status: Accepted

Solution code:
def main():
  A,B,C,K = map(int, input().split())
  
  sum = 0
  
  if K > A:
    sum += 1 * A
  elif K <= A:
    sum += 1 * K
  
  if K > A + B:
    sum += -1 * (K - (A + B))
  
  print(sum)
  
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:
    tmp = K - (A + B)
    print(A - tmp)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(A, B, C, K):
  card_counts = [A,B,C]
  card_points = [1,0,-1]
  card_remain = K
  max_point = 0
  
  for i in range(3):
    if card_remain > card_counts[i]:
      card_remain -= card_counts[i]
      max_point += card_counts[i] * card_points[i]
    else:
      max_point += card_remain * card_points[i]
      break
  return max_point

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(a-k)

Submission status: Accepted

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

Submission status: Accepted

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