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:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(A: int, B: int, C: int, K: int):
    return min(K, A) - max(K-A-B, 0)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(A, B, C, K))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

# kがaより多い

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

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

Submission status: Accepted

Solution code:
import sys
A,B,C,K=map(int, sys.stdin.readline().split())
ans=0
a_cards=min(K,A)
K-=a_cards
ans+=a_cards*1

b_cards=min(K,B)
K-=b_cards
ans+=b_cards*0

c_cards=min(K,C)
K-=c_cards
ans+=c_cards*-1

print ans

Submission status: Accepted

Solution code:
import sys

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

if not ( 0 <= A and 0 <= B and 0 <= C ): sys.exit()
if not ( 1 <= K <= A+B+C and A+B+C <= 2 * 10**9 ): sys.exit()

sum = 0
if A >= 1 and K <= A:
    print(K)
    sys.exit()
elif A >= 1 and K > A:
    sum += A
    K -= A
    A = 0

if B >= 1 and K <= B:
    print(sum)
    sys.exit()
elif B >= 1 and K > B:
    K -= B
    B = 0

if C >= 1 and K <= C:
    sum -= K
    C = 0
elif C >= 1 and K > C:
    sum -= C
    print(sum)
    sys.exit()

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

ans=0
A, B, C, K = (int(x) for x in input().split())

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int,input().split())
if K <= A:
    print(K)
elif K <= A+B:
    print(A)
else:
    print(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(x) for x in input().split()]
result = 0
if K > A:
    result += A
else:
    print(K)
    exit()

if K < A + B:
    print(result)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

a, b, c, k = LI()

# m = max[a, b, c]
# if k - m >

x = k - a
y = x - b
z = y - c

if x <= 0:
    print(k)
    sys.exit()
elif (x > 0) and (y <= 0):
    print(a)
    sys.exit()
elif (y > 0):
    print(a - y)
    sys.exit()

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

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

Submission status: Accepted

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

count = 0
if a < k:
    count += a
    if a+b < k:
        count -= k-a-b
else:
    count = k

print(count)

Submission status: Accepted

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


sum = 0
rest_k = k

if rest_k <= a:
    sum += rest_k
    rest_k = 0
else:
    sum += a
    rest_k -= a

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

sum -= rest_k

print(sum)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
a,b,c,k = MI()
if a+b >= k:
    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+B>K):
    print(A)
else:
    print(A-(K-(A+B)))

Submission status: Accepted

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

num_one_cards = min(a, k)
num_zero_cards = min(b, k - num_one_cards)
num_minus_one_cards = k - num_one_cards - num_zero_cards

score = 1 * num_one_cards + 0 * num_zero_cards + (-1) * num_minus_one_cards

print(score)

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

Submission status: Accepted

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

Submission status: Accepted

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

score = 0
if K <= A:
    score =  K
    print( score )
    exit()

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

K -= B
print( score - K )

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
l = {1: a, 0: b, -1: c}
ans = 0
for i, j in l.items():
    if k >= j:
        ans += j * i
        k -= j
    else:
        ans += k * i
        break
print(ans)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
if a[3] <= a[0]:
  print(a[3])
elif a[3] <= a[0] + a[1]:
  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())
answer = 0
answer += min(A, K)
K = K - A - B
if K > 0:
    answer -= min(C, K)
print(answer)

Submission status: Accepted

Solution code:
a,b,c,k = list(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 k<=a:
    print(k)
elif a<k<=(a+b):
    print(a)
else:
    print(a+(k-a-b)*(-1))

Submission status: Accepted

Solution code:
tmp = input().split()
a = int(tmp[0])
b = int(tmp[1])
c = int(tmp[2])
k = int(tmp[3])
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:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

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


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if a >= k:
    print(k)

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

Submission status: Accepted

Solution code:
a, b, c, x = map(int, input().split())
total = 0
lst = {1:a, 0:b, -1:c}
for k, v in lst.items():
    if x:
        if x == v:
            total += k * v
            x -= v
        elif x > v:
            total += k * v
            x -= v
        else:
            total += k * x
            x -= x

print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
    Satwik_Tiwari ;) .
    12th july , 2020  - Sunday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

from itertools import *
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bfs(g,st,lcatable,level):
    visited = [0]*(len(g))
    visited[st] = 1
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == 0):
                level[i] = level[s]+1
                lcatable[i][0] = s
                visited[i] = 1
                queue.append(i)

    return new

def lcatable(g,n,level): #O(nlogn) make table beforehand.to answer per query in O(logn)
    mx = 0
    while(2**(mx) <=n):
        mx+=1
    # print('mx',mx)
    lcatable = [[-1]*mx for i in range(n+1)]
    bfs(g,1,lcatable,level)

    for j in range(1,mx):
        for i in range(1,n+1):
            if(lcatable[i][j-1] != -1):
                lcatable[i][j] = lcatable[lcatable[i][j-1]][j-1]

    return lcatable

def dist(x0,y0,x1,y1):
    return (abs(x0-x1) + abs(y0-y1))

def djkistra(g,st,dist): #g contains b,dist(a to b) and dist is initiaalised by 10**9 initiallly
    pq = []
    dist[st] = 0
    pq.append([0,st])
    while(len(pq) != 0):
        curr = heappop(pq)[1]
        for i in range(0,len(g[curr])):
            b = g[curr][i][0]
            w = g[curr][i][1]
            if(dist[b] > dist[curr] + w):
                dist[b] = dist[curr]+w
                pq.append([dist[b],b])
    return dist

# ini = 10**5
def solve():
    a,b,c,k = sep()
    ans = 0
    if(k>a):
        ans+=a
        k-=a
        if(k>b):
            k-=b
            ans-=k
    else:
        ans +=k
    print(ans)

testcase(1)
# testcase(int(inp()))

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-b-a))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, d = map(int, input().split())
if d < a:
  print(d)
  exit()
elif d < a + b:
  print(a)
  exit()
else:
  print(a+(-1)*(d-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:
# B Easy Linear Programming

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

if K > 0:
    ans += min(K, B) * 0
    K -= B

if K > 0:
    ans += min(K, C) * (-1)
    K -= C

print(ans)

Submission status: Accepted

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

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:
a, b, c, k = map(int, input().split())

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

Submission status: Accepted

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

ans = 0

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

k -= a
ans += a

if k <= b:
  print(ans)
  exit()

k -= b
print(ans - k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().split())
count=0
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())
#l = [1 for i in range(a)] + [0 for i in range(b)] + [-1 for i in range(c)]
#ans = sum(l[:k])
if k <= a:
    ans = k
elif (a < k) & (k <= a + b):
    ans = a
elif (a + b < k) & (k <= a + b + c):
    ans = a - (k - (a + b))

print(ans)

Submission status: Accepted

Solution code:
import sys
def main():
  a ,b ,c ,k = list(map(int,input().split()))
  if k > a:
    ans = a*1
    k-= a
  else:
    ans = (k)*1
    k = 0
#  print('a',k,ans)
  if k > b:
    k-= b
  else:
    k = 0
#  print('b',k,ans)
  if k > c and k>0:
    ans += (c)*-1
  else:
    ans += (k)*-1
    
  print(ans)   
#  print(k,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(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:
S = input().split( ) 
a=int(S[0]) 
b=int(S[1])
c=int(S[2])
k=int(S[3])
t=2*a+b-k
if k <= a:
  print(str(k))
elif a < k <= a + b:
  print(str(a))
else: print(str(t))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Xa = min(K,A)
K2 = K - Xa
Xb = min(K2,B)
Xc = K2 - Xb

print(Xa - Xc)

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

count_A = 0
count_B = 0
count_C = 0
count = 0
if A >= K:
    count_A += K
else:   # A < K
    K -= A
    count_A += A
    if B >= K:
        count_B += K
    else:
        K -= B
        count_B += B
        count_C += K

print(count_A - count_C)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

re = k
na = min(a, re)
re -= na
nb = min(b, re)
re -= nb
nc = min(c, re)

print(na - nc)

Submission status: Accepted

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

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

K -= B

if K > 0:
    ans -= K

print(ans)

Submission status: Accepted

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

a,b,c,k = list(map(int,input().split()))
if k<a:
    print(k)

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

Submission status: Accepted

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

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 = list(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

ans -=k

print(ans)

Submission status: Accepted

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

cnt=0

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

Submission status: Accepted

Solution code:
def main():
    A, B, C, K = map(int, input().split())
    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:
# B - Easy Linear Programming
A,B,C,K = map(int,input().split())
while True:
    ans = 0
    ans += min(A,K)
    K -= min(A,K)
    if K<=0:
        break
    K -= B
    if K<=0:
        break
    ans -= K
    break
print(ans)

Submission status: Accepted

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

ans = a

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

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
ans=0
if not a<d:
  print(d)
else:
  if not a+b<d:
    print(a)
  else:
    print(2*a+b-d)

Submission status: Accepted

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

Submission status: Accepted

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


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

print(ans)

Submission status: Accepted

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

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

print (_sum)

Submission status: Accepted

Solution code:
#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    A,B,C,K = map(int, input().split())
    print(min(A,K)-max(0,min(C, K-A-B)))

main()

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = map(int, input().split())
    if a+b >= k:
        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 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)>0):
    Y = K-A
else:
    print(K)
    exit()
if((Y-B)>0):
    Z = Y-B
else:
    Z = 0

X = A + 0 * Y + (-1) * Z
print(X)

Submission status: Accepted

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

ans = 0
if A >= K:
  ans = K

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
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())
num = 0

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

print(num)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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