Problem:


Score : 200 points

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

0 \leq A, B, C

1 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with 1s and one card with a 0.
In this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000



Sample input:
2 1 1 3


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

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

c1 = A+B
c2 = A+B+C

if K<A: num = K
elif K>c1 and K<=c2:num = A - (K-A-B)
else:num = A

print(num)

Submission status: Accepted

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

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

if c > k:
    ans += -1*k
    print(ans)
    exit()
else:
    ans += -1*c

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

s = list(map(int,input().split()))
a=s[0]
b=s[1]
c=s[2]
k=s[3]
if a+b<k:
    print(a-(k-a-b))
else:
    if a>k:
        print(k)
    else:
        print(a)

Submission status: Accepted

Solution code:
s = input("")
L = s.split(" ")
a,b,c,k = int(L[0]),int(L[1]),int(L[2]),int(L[3])
if (k<=a):
	print (k)
elif (a<k and k<=(a+b)):
	print (a)
elif ((a+b)<k and k<=(a+b+c)):
	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 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:
    print(K)
elif K>A and K<=A+B:
    print(A)
elif K>A+B:
    print(A-(K-(A+B)))

Submission status: Accepted

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

val=0

if k<=a:
    val+=k
else:
    val+=a

if k-a-b>0:
    val-=k-a-b

print(val)

Submission status: Accepted

Solution code:
A,B,C,K=[int(x) for x in input().rstrip().split()]
num=A+B
if K<=A:
  print(K*1)
elif K<=A+B:
  print(A*1)
else:
  print((A)*1+(K-(A+B))*-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sum = 0
cnt = K
if A>=cnt:
	sum += cnt*1
else:
	sum += A*1
	cnt = cnt-A
	if B >= cnt:
		sum+= cnt*0
	else:
		sum += B*0
		cnt = cnt-B
		if C >= cnt:
			sum += cnt*(-1)
		else:
			sum += C*(-1)
print(sum)

Submission status: Accepted

Solution code:
#coding:utf-8

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

if K <= A:
    print("{}".format(K))
elif K <= A+B:
    print("{}".format(A))
else:
    print("{}".format(A-(K-A-B)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    A, B, C, K = map(int, input().split())
    AC = min(K, A)
    BC = min(K - AC, B)
    CC = min(K - AC - BC, C)
    print(1*AC+0*BC+(-1)*CC)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

total = min(A, K)
K -= (A + B)
if 0 < K:
    total -= min(C, K)

print(total)

Submission status: Accepted

Solution code:
t=[int(x) for x in input().split()]
a=t[0]
b=t[1]
c=t[2]
k=t[3]
if k<=a:
    print(k)
else:
    ans=a
    rem=k-a
    if rem<=b:
        print(ans)
    else:
        rem=rem-b
        val=-1*rem
        ans=ans+val
        print(ans)

Submission status: Accepted

Solution code:
import sys

import math
input = sys.stdin.readline
A,B,C,K = map(int,input().split())
    
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else :
    F = K - (A+B)
    print (A - F )

Submission status: Accepted

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

  if A >= K:
    print(K)
    return True

  result = 0
  K = K - A
  result = A

  if B >= K:
    print(result)
    return True

  K = K - B

  print(result - K)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def cal():

    a, b, c, k = input().split(" ")
    a = int(a)
    b = int(b)
    c = int(c)
    k = int(k)
    ans = 0
    if k <= a:
        ans = k
    elif a < k <= (a+b):
        ans = a
    elif k > (a+b):
        ans = a - (k - (a+b))
    print(ans)



cal()

Submission status: Accepted

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

Submission status: Accepted

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

if K<=A:
  print(K)

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    a, b, c, k = map(int, input().split())
    result = 0

    result += min(k, a)
    k -= min(k, a)
    k -= min(k, b)
    result -= min(k, c)

    print(result)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int,input().split())
result = 0
List = []
if A >= K:
  result = K
elif A + B >= K:
  result = A
elif A + B + C >= K:
  result = A + (K - A - B )*(-1)
  

print(result)

Submission status: Accepted

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


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

Submission status: Accepted

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

x = 0
if K >= A:
    x += A
    K = K - A
    #print(K)
    if K >= B:
        K = K - B
        #print(K)
        if K >= C:
            x += -1 * C
        else:
            x += -1 * K
    else:
        pass
else:
    x += K
print(x)

Submission status: Accepted

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

cnt = K
sum_ = 0
if K <= A:
    print(K)
    exit()
else:
    sum_ += A
    cnt -= A

if cnt <= B:
    print(sum_)
    exit()
else:
    cnt -= B

print(sum_ - min(cnt, C))

Submission status: Accepted

Solution code:


def main():
    ABCK = list(map(int,input().split()))

    AB = ABCK[0] + ABCK[1]


    if ABCK[0] > ABCK[3]:
        print(ABCK[3])

    elif ABCK[3] > AB:
        kk = ABCK[3]-AB

        # print(kk)

        print(ABCK[0]-(kk))

    else:
        print(ABCK[0])


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

if a >= k:
    ans = k

elif a + b >= k:
    ans = a

else:
    buf = k - (a + b)
    ans = a - buf

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

Submission status: Accepted

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

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

if a >= k:
    print(k)
elif a < k and a+b >= k:
    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 K > A:
  a = A
  if K >= A+B:
    c = K - A -B
    print(A-c)
  else:
    print(A)
else:
  a = K
  print(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:
A, B, C, K = [ int(i) for i in input().strip().split(' ') ]
n_a = min(A, K)
n_b = min(B, K-n_a)
n_c = min(C, K-n_a-n_b)
print(n_a-n_c)

Submission status: Accepted

Solution code:
from typing import NoReturn


def main() -> NoReturn:
    a, b, c, k = map(int, input().split())  # type: int, int, int, int
    if a >= k:
        print(k)
    elif a + b >= k:
        print(a)
    else:
        print(2 * a + b - k)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A, B, C, K = (int(x) for x in input().split())
max = 0
if K <= A:
    print(K)
else:
    Kb = K - A
    if Kb <= B:
        print(A)
    else:
        Kc = Kb - B
        print(A-Kc)

Submission status: Accepted

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

def main():

    n = [int(x) for x in input().split(' ')]
    a = n[0]
    b = n[1]
    c = n[2]
    k = n[3]

    point = 0
    count = k

    a_ = a
    a_b = a + b
    if k <= a:
        point = k
    elif k >= a and k <= a+b:
        point = a
    else:
        take_c = k - (a + b)
        point = a - take_c

    # 出力
    print(point)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

a, b, c, k = MAP()
k -= a
res = a
if k <0:
    res += k
if k>0:
    k -= b
    
if k>0:
    k -= c
    res -=c
    if k<0:
        res -=k
print(res)

Submission status: Accepted

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

ans = 0

nokori = K

# まず1の札を取れるだけ取る
if A >= K:
  # Aのほうが多い場合
  ans = ans + K
  K = 0
else:
  # Aのほうが少ない場合
  ans = A
  K = K - A

# 次に0の札を取れるだけ取る
K = K - B

# まだ取れる枚数が残っている場合、最大C枚取る
if K > 0:
  ans = ans - min(C, K)

print(ans)

Submission status: Accepted

Solution code:
data = input().split(" ")
A = int(data[0])
B = int(data[1])
C = int(data[2])
K = int(data[3])
ans = 0
if A >= K:
    ans = K
else:
    K -= A
    ans += A
    if B >= K:
        pass
    else:
        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 A <= K <= A+B:
    print(A)
elif A+B < K <A+B+C:
    print(A - (K - (A+B)))
else:
    print(A-C)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B

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

Submission status: Accepted

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

else:
    print(K)

Submission status: Accepted

Solution code:

a, b, c, k = (int(x) for x in input().split())

count = 0

if k <= a :
    count = 1 * k
else :
    if k <= a:
        count = 1 * a
    else : 
        count = 1 * a + -1 * (k - a - b)

print(count)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

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

num = 0

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

Submission status: Accepted

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

if b >= k:
    print(ans)
    quit()
else:
    k-=b
    ans += (-1*k)
    print(ans)

Submission status: Accepted

Solution code:
def main():
    A,B,C,K = list(map(int, input().split(' ')))
    
    out = 0
    if A > K:
        out = K
        return out
    else:
        nokori = K-A
        if nokori <= B:
            out = A
            return out
        elif nokori > B:
            nokonkori = K - A - B
            out = A - nokonkori
            return out
            
            
            
            
out = main()
print(out)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque

#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp
		


a,b,c,k=input2()


count=0
if k<a:
	count=k
elif k>=a and k<b:
	count=a
else:
	count=a-(k-a-b)
print(count)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
ans = min(a,k)
k -= ans
num = min(b,k)
k -= num
print(ans-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, K = map(int,input().split())

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

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

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

print(ans)

Submission status: Accepted

Solution code:
# Problem B - Easy Linear Programming

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

# initialization
ans = 0
# calc a
nokori = K
if nokori>=A:
    ans += 1 * A
    nokori -= A
else:
    ans += 1 * nokori
    nokori = 0

# calc b
if nokori>=B:
    nokori -= B
else:
    nokori = 0

# calc c
ans -= 1 * nokori

# output
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

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

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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    A, B, C, K = [int(i) for i in input().split()]

    ans = 0

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

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

    return ans-K


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if K <= A:
    score = K
else:
    score = A
    K -= A
    if K <= B:
        score += 0
    else:
        score += 0
        K -= B
        score -= K

print(score)

Submission status: Accepted

Solution code:
# # for i in range(m):
# s = input()
# t = input()
# n = len(s)
# m = len(t)
# # print(s,t,n,m)
# if n+1==m:
# 	for i in range(n):
# 		# print(s[i], t[i])
# 		if s[i]!=t[i]:
# 			print("No")
# 			break
# 	else:
# 		print("Yes")
# else:
# 	print("No")
	# l, r = [int(j)-1 for j in input().split()]
	################
def fun(a,b,c,k):
	ans =0 
	if k<=a:
		return k
	else:
		ans = a
		k-=a
	if k<=b:
		return ans
	else:
		k-=b
	# if k<=c:
	# print(ans, c)
	return ans-min(c,k)
a,b,c,k = [int(j) for j in input().split()]
# l = [a,b,c]
# j = 0
print(fun(a,b,c,k))


# while(k>0):
# 	a = min(k, l[j])
# 	k-=a

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

t= 0

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

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

if k < c:
    t += k*-1
    k = 0
else:
    t += c*-1

print(t)

Submission status: Accepted

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

import sys

ans = 0

if k >= a:
    ans += (1*a)
    k -= a
else:
    ans += (1*k)
    print(ans)
    sys.exit()

if k >= b:
    k -= b
else:
    print(ans)
    sys.exit()

if k ==  c:
    ans += ((-1)*c)
else:
    ans += ((-1)*k)

print(ans)

Submission status: Accepted

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

# from fractions import gcd
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

A, B, C, K= [int(_) for _ in input().split()]

ct = 0
k = K - A
if k >= 0:
    ct += A
else:
    ct += K

k = k - B
if k > 0:
    ct -= k
print(ct)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

if a<=k:
  sum+=a
  k-=a
  
else:
  sum+=k
  print(sum)
  sys.exit()

k-=b

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-05-10 21:07:27 +0900
# LastModified: 2020-05-10 21:10:45 +0900
#


import os
import sys


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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

    elif b>0:
        if k>=b:
            sum+=0
            k=k-b
            b=0
        else:
            sum+=0
            k=0
    else:
        sum-=k
        k=0
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if a >= k:
    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()) 

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = map(int, input().split())
    ans = solve(a, b, c, k)
    print(ans)


def solve(a, b, c, k):
    ca, cb, cc = 0, 0, 0
    ca = min(a, k)
    k -= ca
    cb = min(b, k)
    k -= cb
    cc = min(c, k)
    k -= cc
    ans = ca * 1 + cb * 0 + cc * (-1)
    return ans


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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	a, b, c, k = map(int, sys.stdin.readline().split())
	ans = 0
	if k <= a:
		print(k)
	elif k <= a + b:
		print(a)
	elif k <= a + b + c:
		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 a < k <= a+b:
    print(a)
else:
    hami = k - a - b
    print(a - hami)

Submission status: Accepted

Solution code:
from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
a,b,c,k=map(int,input().split())
su=min(a,k)
k-=min(a,k)
k-=min(b,k)
su-=min(c,k)
print(su)

Submission status: Accepted

Solution code:
def main():
    A,B,C,K = [int(x) for x in input().split()]
    v = 0
    if A<K:
        K -= A
        v += A*1
    else:
        v += K*1
        print(v)
        return
    if B<K:
        K -= B
        v += B*0
    else:
        v += K*0
        print(v)
        return
    if C<K:
        K -= C
        v += C*(-1)
    else:
        v += K*(-1)
        print(v)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B,C,D = map(int,input().split())
AD = D - A
BD = D - A - B
CD = D - A -B - C 
if AD <= 0:
    print(min(A,D))
elif BD <= 0:
    print(A)
else:
    print(A-BD)

Submission status: Accepted

Solution code:
import sys

A,B,C,K = map(int, sys.stdin.readline().strip().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 a>=k:
  print(k)
elif a+b>=k:
  print(a)
else:
  print(a-(k-a-b))

Submission status: Accepted

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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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