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
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools
import heapq
#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    a,b,c,k=map(int,input().split())
    ans=0
    while True:
        if a>=k:
            ans=k
            break
        else:
            ans+=a
            k-=a
        if b>=k:
            break
        else:
            k-=b
        ans-=k
        break
    print(ans)







if __name__ == "__main__":

    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

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

if k>0 and c>0:
    ans-=k

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


def compute(a, b, c, k):
    res = 0
    num_a = min(k, a)
    res += num_a
    k -= num_a
    num_b = min(k, b)
    k -= num_b
    num_c = min(k, c)
    res -= num_c
    return res


def main():
    a, b, c, k = (int(z) for z in input().split())
    res = compute(a, b, c, k)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
if A >= K:
    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] = [int(s) for s in input().split()]

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

Submission status: Accepted

Solution code:

def q2():
    A, B, C, K =  [int(i) for i in input().split(" ")]
    if K <= A:
        print(K)
        return
    if K <= A + B:
        print(A)
        return
    print(A+(K-(A+B))*-1)
    

q2()

Submission status: Accepted

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

print(ans-k)

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(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:
import sys
def S(): return sys.stdin.readline().rstrip()
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 = LI()

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

print(result)

Submission status: Accepted

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

print( min(a,k)+min(0,a+b-k))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

A, B, C, K = rl()

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

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

print(count)

Submission status: Accepted

Solution code:
import math
import fractions
import collections
import itertools
A,B,C,K=map(int,input().split())

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

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

if A >= K:
    print(K)

elif A + B >= K:
    print(A)

else:
    c = K - (A + B)
    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:
    m = k - (a + b)
    print(a-m)

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

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 = list(map(int, input().split()))

A_ = min(A, K)
K -= A_
B_ = min(B, K)
K -= B_
C_ = min(C, K)

print(A_ * 1 + B_ * 0 + C_ * -1)

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-(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:
# ABC167b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    a, b, c, k = map(int, input().split())
    at = min(a, k)
    nk = k-at
    bt = min(b, nk)
    nk = nk-bt
    ct = min(c, nk)
    print(at - ct)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

sumi = 0


sumi += min(a, k)
k -= min(a, k)
if k > 0:
  k -= min(b, k)
if k > 0:
  sumi -= min(c, k)
  k -= min(c, k)

print(sumi)

Submission status: Accepted

Solution code:
A, B, C, K = [int(x) for x in 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
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

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

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

ans -= k
print(ans)

Submission status: Accepted

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

# if b + c >= k:
#     saisho = -min(c, k)
# else:
#     saisho = -c + (k - (b + c))
print(saidai)

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 = list(map(int, input().split()))

rest = K

a = min(A, rest)
rest = rest - a

b = min(B, rest)
rest = rest - b

c = min(C, rest)
rest = rest - c

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

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

if k>0:
    k -= b

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

print(ans)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)
###################################################

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ma():
    return map(int,input().split())
y="Yes"
t="No"
a,b,c,k=ma()
if a+b>=k:
    print(min(a,k))
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())

print(min(a,k)-max(k-(a+b),0))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

A,B,C,K = LI()

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

print(current)

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

ans = 0
num = min(a, k)
ans += num
k -= num

if k == 0:
    print(ans)

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect
import collections
import heapq
import math
import operator as op
from collections import Counter
from functools import reduce

import numpy as np


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    A, B, C, K = get_inputs(int)

    ans = 0
    if K > 0:
        N = min(K, A)
        ans += N
        K -= N

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

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

    assert K == 0
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,c,k = mi()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import itertools
import math
a,b,c,k = ma()
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)
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
n = min(A, K)
ans += n
K -= n
if K == 0:
    print(ans)
    exit()
n = min(B, K)
K -= n
if K == 0:
    print(ans)
    exit()
n = min(C, K)
ans -= n
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def examA():
    S = SI()
    T = SI()
    if S==T[:len(S)]:
        if len(S)+1==len(T):
            print("Yes")
            return
    print("No")
    return

def examB():
    A, B, C, K = LI()
    ans = 0
    if A>=K:
        ans = K
    else:
        ans += A
        K -= A
        if K>B:
            K -= B
            ans -= K
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

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

x = min(a, k)
res += 1 * x
k -= x

x = min(b, k)
res += 0 * x
k -= x

x = min(c, k)
res += -1 * x
k -= x

print(res)

Submission status: Accepted

Solution code:
def main():

    import sys, math
    #from bisect import bisect_left as bl, bisect_right as br, insort
    #from heapq import heapify, heappush, heappop
    #from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return list(map(int, data().split()))
    def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
    # sys.setrecursionlimit(100000)
    INF = int(1e9)
    mod = int(1e9)+7

    a,b,c,k=mdata()
    if k>a:
        if k>b:
            print(a-(k-a-b))
        else:
            print(a)
    else:
        print(k)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = [int(i) for i in input().split()]
ans = 0
ans += min(A, K)
K = max(K - A, 0)
K = max(K - B, 0)
ans -= min(C, K)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

Solution code:
a, b, c, k = [int(i) for i in input().split()]
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
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())
total = 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 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 = [int(_) for _ in 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]=list(map(int,input().split()))
if k<a:
    ans=k
elif a<=k<a+b:
    ans=a
elif a+b<=k:
    ans=2*a+b-k
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# 
# s = input()

a, b, c, k = list(map(int, input().split()))
ans = 0
if k > 0:
    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=list(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 = [int(e) for e in input().split()]
if k <= a:
    print(k)
elif k<a + b:
    print(a)
else:
    print(a-(k-a-b))

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B,C,K = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    if A>=K:
        cnt = 1*K
    elif A+B>=K:
        cnt = 1*A
    else:
        cnt = 1*A-1*(K-A-B)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b, c, k = nm()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq

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

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

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

k-=b
print(a-k)

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

Submission status: Accepted

Solution code:
import sys

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

def main():
    if k <= a + b:
        print(min(a, k))
    else:
        print(a - (k - (a + b)))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = min(a, k)

ans -= max(0, k - (b + a))

print(ans)

Submission status: Accepted

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

result = 0
t = min(A, K)
result += t
K -= t
t = min(B, K)
K -= t
t = min(C, K)
result -= t
print(result)

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

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit
# from collections import defaultdict

geta = lambda fn: list(map(fn, input().split()))

a, b, c, k = geta(int)

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