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:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations
#import bisect# lower_bound etc
#import numpy as np
def run():
    A,B,C,K = map(int, sysread().split())
    ret = 0
    for i, x in zip((1,0,-1), (A, B, C)):
        tmp = min(x,K)
        K -= tmp
        ret += tmp * i
        if K == 0:break
    print(ret)
if __name__ == "__main__":
    run()

Submission status: Accepted

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


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


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


solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    A, B, C, K = [int(item) for item in input().split()]

    A_max = min(A, K)
    B_max = min(B, K - A_max)
    C_max = K - A_max - B_max

    print(A_max - C_max)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def run():
    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__':
    run()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


    
a,b,c,k=mi()
s=0
if(k>=a):
    s+=a
    k-=a
    if(k>=b):
        k-=b
    # print(k,a,s)
    if(k>0):
        s-=k
    print(s)
else:
    print(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()

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:
def mips():
    return map(int,input().split())
def msps():
    return map(str,input().split())

import sys
A,B,C,K = mips()
ans = 0
reste = K
if A >= K:
    print(K)
    sys.exit(0)
if A < K:
    ans += A
    reste -= A
if reste <= B:
    print(ans)
    sys.exit(0)
reste -= B
if reste <= C:
    ans -= reste
    print(ans)
else:
    ans -= C
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def task(a, b, c, k):
    pluses = min(a, k)
    zeros = min(b, k - pluses)
    minuses = min(c, k - pluses - zeros)

    total = pluses - minuses
    print(total)


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

Submission status: Accepted

Solution code:
def main():
    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)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
a, b, c, k = (int(x) for x 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:
def wa(a,b,c,k):
    if k <= a:
        print(k)
    elif a < k <= b:
        print(a)
    else:
        print(a-(k-a-b))

a,b,c,k = [int(i) for i in input().split()]
wa(a,b,c,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())

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

def main(A, B, C, K):
  point = 0
  if K<=A:
    return K
  point += A
  K -= A
  if K<=B:
    return point
  K -= B
  return point-K

print(main(A, B, C, K))

Submission status: Accepted

Solution code:
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))

def case():
    a,b,c,k=li()
    ans=0
    if(k>=a):
        ans+=a
        k-=a 
    else:
        ans=k
        k=0
   # print(ans)
    if(k>=b):
        ans+=0
        k-=b 
    else:
        k=0 
    if(k>=c):
        ans-=c
    else:
        ans-=k 
    print(ans)

for _ in range(1):
    case()

Submission status: Accepted

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

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

Submission status: Accepted

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

m = 0


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

print(m)

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

summ = min(K, A)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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


solve()

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    res = 0

    if A >= K:
        res += K
        K = 0
    else:
        res += A
        K -= A

    if B >= K:
        K = 0
    else:
        K -= B

    if C >= K:
        res -= K
        K = 0
    else:
        res -= A
        K -= C

    print(res)


main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

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

    if k <= a:
        print(k)
        return
    
    if k <= (a+b):
        print(a)
        return
    x=k-(a+b)
    print(a-x)

    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

else:
    print(a+b+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(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 = list(map(int, input().split()))
res = min(a, k)
f = True
k -= min(a, k)
if k == 0:
    print(res)
    f = False
k -= min(b, k)
if k == 0 and f:
    print(res)
    f = False
res -= min(c, k)
if f:
    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:
    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(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:
    res = k - (a + b)
    print(a- 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(a-(k-a-b))

Submission status: Accepted

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

n = 0
if k >= a:
    n += a
    k -= a
else:
    n = k
    k = 0

k -= b

if k >= 0:
    n -= max(k, 0)
print(n)

Submission status: Accepted

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

n = min(a, k)
ans = n
k -= n

n = min(b, k)
k -= n

n = min(c, k)
ans -= n

print(ans)

Submission status: Accepted

Solution code:
## coding: UTF-8
A, B, C, K = map(int,input().split())

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

print(res)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

ans = a
k = k - a

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

k = k - b
ans = ans - k
print(ans)

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

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 = (int(x) for x in input().split())
ans = 0
num = 0
if k<=a:
    print(k)
else:
    if 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 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 B >= K - A:
    print(A)
  else:
    print(A - (K - A - B))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
inp=input
li=list
iinp=lambda : int(inp())
ent=lambda : map(int,inp().split())
lient=lambda : [int(i) for i in inp().split()]
li0= lambda x: [0 for i in range(x)]
livalor=lambda valor,x: [valor for i in range(x)]
stent=lambda : [i for i in inp()]
filldp=lambda valor,x,y: [[valor for i in range(y)] for i in range(x)]

a,b,c,k=ent()
res=a if a<=k else k
k=k-a
if k<=0:
    print(res)
else:
    k=k-b
    if k<=0:
        print(res)
    else:
        res=res-k if k<=c else res-c
        print(res)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


def main():
    A, B, C, K = readnums()
    if A > K:
        print(K)
    elif A + B >= K:
        print(A)
    elif A + B < K:
        print(A - (K - (A + B)))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

res=0
res+=min(k,a)
k-=min(k,a)

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

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

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    a, b, c, k = LI()
    num = 0
    if k < a:
        num = k
        print(num)
        return

    k -= a
    num += a
    if k < b:
        print(num)
        return
    k -= b

    if k < c:
        num -= k
        print(num)
        return
    k -= c
    num -= c
    print(num)
main()

Submission status: Accepted

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

Submission status: Accepted

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

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:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
A, B, C, K = M()
ans = 0
if A < K:
    ans += A
    K -= A
    if B < K:
        K -= B
        ans -= K
else:
    ans = K
print(ans)

Submission status: Accepted

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

point = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
if a[0]>=a[3]:
  print(a[3])
elif a[0]+a[1]>=a[3]:
  print(a[0])
else:
  print(a[0]-(a[3]-a[0]-a[1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    a,b,c,k = map(int, input().split())
    if a > k:
        ans = k
    elif a + b < k:
        c_n = k - (a+b)
        ans = a - c_n
    else:
        ans = a
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

ans = 0

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

if K >= B:
    K -= B
else:
    K = 0

if K >= C:
    ans -= C
    K -= C
else:
    ans -= K
    K = 0

print (ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

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

Submission status: Accepted

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

else:
    cnt += k
    

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

a, b, c, k = list(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(x) for x in input().split())
ans = 0
if(A>=K):
    ans = K
elif(A+B>=K):
    ans = A
elif(A+B+C>=K):
    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<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:
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------

a,b,c,k = mapi()
res = 0
res,k = min(k,a),max(0,k-min(k,a))
k = max(k-min(k,b),0)
res-=min(k,c)
print(res)

Submission status: Accepted

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

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

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

print(a-k)

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = (int(i) for i in input().split())
    if k < a:
        ans = k
    elif k == a:
        ans = a
    elif a < k and k <= a+b:
        ans = a
    elif a+b < k:
        ans = a
        k -= a+b
        ans -= k
    print(ans)


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

Submission status: Accepted

Solution code:
import sys

A, B, C, K = map(int, sys.stdin.readline().strip().split())

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

print(a - c)

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def abc167_b():
    A, B, C, K = map(int, input().split())
    ans = min(A, K)
    if A + B < K:
        ans -= K - (A + B)
    print(ans)

abc167_b()

Submission status: Accepted

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

Submission status: Accepted

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

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

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
    k = 0
if b <= k:
    k -= b
else:
    k = 0
if c <= k:
    ans -= c;
    k -= c
else:
    ans -= k
    k = 0


print(ans)

Submission status: Accepted

Solution code:
a,b,c,k=(int(i) for i in 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())

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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:
#!/usr/bin/env python3

# N = int(input())
# S = input()
A, B, C, K = map(int, input().split())
# A = list(map(int, input().split()))

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

#print(a,b,c)
print(a-c)

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

Submission status: Accepted

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