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 -*-
# スペース区切りの整数の入力
A, B, C, K = map(int, input().split())
# 文字列の入力
#s = input()
#開業されたN個要素を受け付ける
#list = [input() for i in range(N)]

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

print(ans)

Submission status: Accepted

Solution code:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions

t = [int(s) for s in stdin.readline().rstrip().split()]

if t[3] <= t[0]:
    print(t[3])
else:
    if t[3] <= t[0] + t[1]:
        print(t[0])
    else:
        if t[3] <= t[0] + t[1] + t[2]:
            print(t[0]-(t[3]-t[1]-t[0]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    a, b, c, k = map(int, input().split())
    ret = 0

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

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

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,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())
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(2*A + B - K)

Submission status: Accepted

Solution code:
import math

(a, b, c, k) = [int(s) for s in input().split()]

s = [(a, 1), (b, 0), (c, -1)]

ans = 0
for (i, v) in s:
    if k - i < 0:
        i = k
    ans += i * v

    k = k - i

    if k == 0:
        break

print(ans)

Submission status: Accepted

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

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

k-=b

ans-=max(0,k)


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ABCK = list(map(int, input().split()))
A = ABCK[0]
B = ABCK[1]
C = ABCK[2]
K = ABCK[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 = map( int, input().split() )

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

print( ret )

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

Submission status: Accepted

Solution code:
inputs = input().split(' ')
cnt_1 = int(inputs[0])
cnt_0 = int(inputs[1])
cnt_m1 = int(inputs[2])
cnts = int(inputs[3])

sum_card = 0
if cnt_1 >= cnts:
    sum_card = cnts
elif cnt_1 + cnt_0 >= cnts:
    sum_card = cnt_1
else:
    sum_card = cnt_1 - (cnts - cnt_1 - cnt_0)

print(sum_card)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a,b,c,k = m()



ans = 0

if a <= k:
    ans += a
    k -= a
    if b <= k:
        k -= b
        if k >= 0:
            ans -= k

else:
    ans += k



print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = [int(i) for i 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:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    A,B,C,K = LI()

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-05-10 20:03
# @url:
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

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


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    abck=list(map(int,input().split()))
    a,b,c,k=abck[0],abck[1],abck[2],abck[3]
    if k<=a+b:
        if k<=a:
            print (k)
        else:
            print (a)
    else:
        x=k-(a+b)
        print (a-x)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import collections

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


ans=0

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

ans+=a
k-=a

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

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

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

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    A, B, C, K = read_ints()
    if A >= K:
        return K
    K -= A
    if B >= K:
        return A
    K -= B
    return A-K


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)
elif (A+B) >= K:
  print(A)
else:
  nok =K-(A+B)
  print(A-nok)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
a,b,c,k = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
if k >= a:
    ans += a
    k -= a
else:
    ans += k
    k = 0
if k >= b:
    k -= b
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 and K<=A+B:
    print(A)
elif K>A+B and K<=A+B+C:
    print(2*A-K+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+(A+B-K))

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
ans = max(min(a,k),0)*1+max(min(b,k-a),0)*0+max(min(c,k-a-b),0)*(-1)
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:
# 2020/05/10
# AtCoder Beginner Contest 167 - B

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

# Calc
if a + b > k:
    ans = min(a, k)
else:
    ans = a - (k - a - b)

# Output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lis = list(map(int,input().split()))
Anum = min(lis[0],lis[3])
Bnum = max(min(lis[1],lis[3]-Anum),0)
Cnum = max(min(lis[2],lis[3]-Anum-Bnum),0)
print(Anum - Cnum)

Submission status: Accepted

Solution code:
a,b,c,k = [int(x) for x in input().split()]
ans = 0
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())
count=K
sum=0
if K<=A:
  sum=K
  print(sum)
else:#残りK-A枚
  sum=A
  if K-A<=B:    
    print(sum)
  else:
    print(sum-(K-A-B))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INT_MAX=10**19+7
MOD=10**12+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
a,b,c,k=INPUT()
ans=0
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:
inpt = input()
inpts = inpt.split()
a = int(inpts[0])
b = int(inpts[1])
c = int(inpts[2])
k = int(inpts[3])

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

Submission status: Accepted

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

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())
print(min(a, k) if a+b > k else a - (k-(a+b)))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
a = i[0]
b = i[1]
c = i[2]
k = i[3]
if k<=a:
    print(k)
elif a < k<=a+b:
    print(a)
elif a+b < k<=a+b+c:
    d = k - (a+b)
    print(a-d)
else:
    print(a-c)

Submission status: Accepted

Solution code:
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    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)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

import sys
input = sys.stdin.readline

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

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

else:
    c_no = k-(a+b)
    print(a-c_no)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 20:54:25 2020

@author: Kanaru Sato
"""

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if A >= K:
    ans=K
else:
    K=K-A
    if B>=K:
        ans=A
    else:
        K=K-B
        ans=A-K

print(ans)

Submission status: Accepted

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

result = 0
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=list(map(int,input().split()))
li=[[1,0,-1],[a,b,c]]
ans=0
for i,l in enumerate(li[1]):
  if k < l:
    ans += li[0][i]*k
    break
  ans += li[0][i]*l
  k -= l
  
print(ans)

Submission status: Accepted

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

x=0
y=0
if(a>=k):
    x=k
    k=0
else:
    x=a
    k=k-a
if(b>=k):
    k=0
else:
    k=k-b
if(c>=k):
    y=k
    k=0
print(x-y)

Submission status: Accepted

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

    ans = 0

    if k >= a:
        ans += a
        if (k-a) >= b:
            ans -= (k-a-b)
    else:
        ans = k
    return ans
def main():
    a, b, c, k = map(int, input().split())
    print(b167(a, b, c, k))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B,C,K = list(map(int , input().split()))
nokori = K 
WA = 0
if K <= A:
    WA = K
elif K > A:
    nokori -=A
    WA += A
    if nokori >B:
        nokori -= B
        WA -=nokori

print(WA)

Submission status: Accepted

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

x = 0
if K < A:
  x += K
if K >= A:
  x += A
if K-A-B >= 0:
  x -= K - A - B
print(x)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

sum = 0

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

K -= B

if K >= 0:
    sum += K * -1

print(sum)

Submission status: Accepted

Solution code:
#import numpy as np
#import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    A = first_input[0]
    B = first_input[1]
    C = first_input[2]
    K = first_input[3]

    nokori_K = K

    if A>=nokori_K:
        print(nokori_K)
        return
    else:
        if B>=(nokori_K-A):
            print(A)
            return
        else:
            print(A-(nokori_K-A-B))
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# = int(input())
A, B, C, K = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

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

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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


if __name__ == '__main__':
    main()

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
    print(ans-k)
  else:
    print(ans)
else:
  print(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

Solution code:
*a, k = map(int, input().split())
res = 0
i = 1
for x in a:
	c = min(k, x)
	k -= c
	res += c * i
	i -= 1

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

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

m = a if a < k else k
m -= max(k - (a + b), 0)

print(m)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
pi = 3.1415926

############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
a,b,c,k = invr()
ans = 0
if k > a:
    ans += a
    k -= a
    if k > b:
        k -= b
        ans += -1*(k)
        print(ans)
    else:
        print(ans)
        
else:
    print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import sys
import math

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

counter = 1
ans = 0

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
a, b, c, k  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

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

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

if c <= k:
    ans -= c
else:
    print(ans - k)
    exit()

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    A, B, C, K = map(int, input().split())
    answer = 0
    if K <= A:
        answer = K
    elif K <= A+B:
        answer = A
    else:
        answer = A - (K -A -B)
    print(answer)

if __name__ == "__main__":
    main()

Submission status: Accepted

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


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

Submission status: Accepted

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

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:
# coding: utf-8


def solve(*args: str) -> str:
    a, b, c, k = map(int, args[0].split())

    ret = min(a, k)
    k -= ret
    k = max(0, k-b)
    ret -= k

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

a1 = min(k, a)
k = max(0, k-a1)
b1 = min(k, b)
k = max(0, k-b1)
# c1 = min(k, b)

print(a1 + (k * -1))

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

Submission status: Accepted

Solution code:

A, B, C, K = map(int, input().split())
cnt = K
ans = 0
if A <= K:
    cnt -= A
    ans += A
    if B <= cnt:
        cnt -= B
        if C <= cnt:
            ans += (-1) * cnt
        else:
            ans += (-1) * cnt
    else:
        ans += 0
else:
    ans += K
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

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


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

def main():
    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
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# @author 

import sys

class BEasyLinearProgramming:
    def solve(self, tc=0):
        a, b, c, k = [int(_) for _ in input().split()]
        print(min(a - max(0, k - a - b), k))


solver = BEasyLinearProgramming()
input = sys.stdin.readline

solver.solve()

Submission status: Accepted

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

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