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

Submission status: Accepted

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

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

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

    ans += K*(-1)

    return ans

print(main())

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

Submission status: Accepted

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

if K - A - B > 0:
    print(1 * A - (K - A - B) * 1)

elif K - A < 0:
    print(1 * K)

elif K - A - B <= 0:
    print(1 * A)

Submission status: Accepted

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

ans = 0

x_a = min(a, k)
ans += x_a
k -= x_a

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

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

print(ans)

Submission status: Accepted

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


if K >= B:
    K = K-B


if K != 0:
    ans = ans-K


print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = []
numA = min([A, K])
numB = min([B, K - numA])
numC = K - numA - numB 

print(numA - numC)

Submission status: Accepted

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

ans += min(a, k)
k -= min(a, k)*1

ans += min(b, k)*0
k -= min(b, k)

ans += min(c, k)*(-1)
k -= min(c, k)

print(ans)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
if k ==0:
  print(k)
elif k <= a :
  print(k)
elif k <= a+b:
  print(a)
else:
  print(((k-(a+b))*-1)+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:
    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 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(a, k))
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:
    print(k)
elif k <= a + b:
    print(a)
else:
    print(f'{2*a + b - k}')

Submission status: Accepted

Solution code:

list_all=list(map(int,input().split()))
if list_all[0]>=list_all[3]:
    print(list_all[3])
elif list_all[0]+list_all[1]>=list_all[3]:
    print(list_all[0])
else:
    print(list_all[0]-(list_all[3]-list_all[0]-list_all[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-(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(2*a + b - k)

Submission status: Accepted

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

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

minus = min(k, c)
res -= minus
k -= minus

print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    a, b, c, k = map(int, input().split())
    if k <= a:
        ans = k
    elif k <= a+b:
        ans = a
    else:
        ans = a - (k - b - a)

    print(ans)
    return
    
main()

Submission status: Accepted

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

ans = 0

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

ans += min(b, k) * 0
k -= min(b, k)

ans += min(c, k) * -1
k -= min(c, k)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding cell (SUBMIT ONLY THIS CELL)

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

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
import sys 
from collections import deque
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def Main():
    a,b,c,k = IL()
    ta = min(k,a)
    tb = min(k-ta,b)
    if tb<0:    tb = 0
    tc = k-ta-tb
    print(ta-tc)
    return

if __name__=='__main__':
    Main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#K枚の優先順位を選ぶ
#＋１の枚数分だけ選択、KからAを引く、総和のリストにA枚分の+1を追加
# K<Aのとき、K枚分だけリストにAを追加、KからKを引く
#0の枚数分だけ選択、KからBを引く、総和のリストにB枚分の0を追加

#・・・総和のリストないの総和を計算する
sum_num = []
card_num = [1,0,-1]
for i,card in enumerate(a[0:3]):
  if card > a[3]:
    sum_num.append(a[3] * card_num[i])
    a[3] -= a[3]
  else:
    sum_num.append(card * card_num[i])
    a[3] -= card
print(sum(sum_num))

Submission status: Accepted

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

print(main())

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:
# B

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    A, B, C, K = map(int, input().split())
    tmp = min(K, A)
    K = K - min(K, A)
    if K == 0:
        print(tmp)
        exit()
    K = K - min(K, B)
    if K == 0:
        print(tmp)
        exit()
    print(A-K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if K > A:
    print(2*A+B-K)
else:
    print(K)

Submission status: Accepted

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

if A >= K:
  print(K)

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

Submission status: Accepted

Solution code:
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:
#!/usr/bin/env python
"""AtCoder Beginner Contest 167: B - Easy Linear Programming
https://atcoder.jp/contests/abc167/tasks/abc167_b
"""


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

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

    print((a * 1) + (b * 0) + (c * -1))


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[a,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())

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

Submission status: Accepted

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

Submission status: Accepted

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

if 0 < k <= a:
    print(k)
elif a < 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:
    res = A
    K = K - A
elif K <= A:
    res = K
    K = 0
if 0 < K and B < K:
    K = K - B
elif 0 < K and K <= B:
    K = 0
if 0 < K:
    res = res - K 
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    A, B, C, K = map(int, input().split())
    print(min(K,2*A+B-K))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
K = int(S[3])
a = min(K, A)
if K >= A:
  a = a + min(K-A, B)*0
  if K-A >= B:
    a = a - min(K-A-B, C)
print(a)

Submission status: Accepted

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

if k-a>0:
  if k-a-b>0:
      ans=2*a+b-k
  else:
    ans=a
else:
  ans=k

print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
p = min(a,k)
k -= p
s = min(b,k)
k -=s
q = min(c,k)

print(p - q)

Submission status: Accepted

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

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

else:
    ans = k

print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
P = min(A, K)
Q = min(B, K-P)
R = K-P-Q
print(P-R)

Submission status: Accepted

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

ans = 0

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

else:
    ans += K

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def Easy_Linear_Programming():
    cards_reguration = input()
    cards = cards_reguration.split()
    A = int(cards[0])
    B = int(cards[1])
    C = int(cards[2])
    K = int(cards[3])
    
    point = 0
    
    if A > 0:
        if A >= K:
            point = K
            print(point)
            return
        else:
            point = A
            K -= A
            if K <= 0:
                print(point)
                return
        
    if B > 0 and K > 0:
        K -= B
        if K <= 0:
            print(point)
            return
        
    if C >= 0 and K > 0:
        point -= K
        print(point)
        return
            
    
Easy_Linear_Programming()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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 = list(map(int, input().split( )))
     
if(K < A):
      score = K
elif(K >= A and K <= A+B):
      score = A
else:
     score = A - (K - A - B)
     
print(score)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(score)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

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

Submission status: Accepted

Solution code:
a, b, c, k =map(int, input().split())  #複数数値入力

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

Submission status: Accepted

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

Submission status: Accepted

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

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())
def max():
  a_0=1
  b_0=-1

  if a>=k:
    print(a_0 * k)
    return
  
  else :
    if k-a<b:
      return

    else:
      d=k-a-b
      print(a_0 * a + b_0 * d)

max()

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

Submission status: Accepted

Solution code:
#ABC167B - Easy Linear Programming
A,B,C,K = map(int,input().split())
if K <= A:
  print(K)
elif A <= K <= A+B:
  print(A)
else:
  l = K - (A+B)
  print(A - l)

Submission status: Accepted

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

out = min(A,K) - max(0,K-A-B)
print(out)

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

if a >= k:
    print(k)
    exit(0)
else:
    p = p + a 
    k = k - a 

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

if c >= k:
    print(p - k)
    exit(0)
else:
    p = p - c

print(p)

Submission status: Accepted

Solution code:
A,B,C,K=map(int,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 (K <= A):
	print(1 * K)
else:
	K1 = K - (A + B)
	if (K1 <= 0):
		print(1 * A)
	else:
		print(1 * A + (-1 * K1))

Submission status: Accepted

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

print(ans-K)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
import sys
def main():
    a,b,c,k=tuple(map(int,sys.stdin.readline().split()))
    print(k) if k<=a else print(a) if k<=a+b else print(2*a+b-k)
if __name__=='__main__':main()

Submission status: Accepted

Solution code:
import sys
def main():
    a,b,c,k=tuple(map(int,sys.stdin.readline().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:
A,B,C,K=map(int,input().split())
if A>=K:
    print(K)
    exit()
elif A+B>=K:
    print(A)
    exit()
else:
    print(A-(K-A-B))
    exit()

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

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(' '))
s = 0
s += min(A, K)
K -= A
K -= B
if K > 0:
    s -= min(C, K)

print(s)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
A, B, C, K = map(int,readline().split())
count = 0

if A >= K:
	print(K)
	sys.exit()

while(K>0):
	if A != 0:
		count += A
		K -= A
		A = 0
	elif B != 0:
		K -= B
		B = 0
	else:
		count -= K
		K = 0
			
print(count)

Submission status: Accepted

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

total = 0

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

Submission status: Accepted

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

out = min(a,k) - max(0,k-a-b)
print(out)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


ans -= K

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:


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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#スペース区切りの文字をint型でリスト化
li = list(map(int,input().split())) #[A,B,C,K]

counter_1=li[0]
counter_0=li[1]
counter_m1=li[2]
counter_choice=li[3]

if counter_choice > counter_1:
    sumpoint=1*counter_1
    counter_choice = counter_choice - counter_1
else:
    sumpoint=1*counter_choice
    print(sumpoint)
    counter_choice=-999

if counter_choice != -999:
    if counter_choice > counter_0:
        sumpoint = sumpoint + 0*counter_0
        counter_choice = counter_choice - counter_0
    else:
        sumpoint = sumpoint + 0*counter_choice
        print(sumpoint)
        counter_choice=-999

if counter_choice != -999:
    if counter_choice > counter_m1:
        sumpoint = sumpoint + (-1)*counter_m1
        counter_choice = counter_choice - counter_m1
    else:
        sumpoint = sumpoint + (-1)*counter_choice
        print(sumpoint)
        counter_choice=-999

Submission status: Accepted

Solution code:
a, b, c, k = (int(i) for i in input().split())
if a >= k:
    ans = k
else:
    if b >= (k-a):
        ans = a
    else:
        ans = a - (k-a-b)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[a, b, c, k] = [int(t) for t in open(0).read().split()]
array = [(a, 1), (b, 0), (c, -1)]
ans = 0
while k > 0 and array:
    tmp = array.pop(0)
    ans += tmp[1] * min(tmp[0], k)
    k -= min(tmp[0], k)
print(ans)

Submission status: Accepted

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

if k > 0:
    if a > k:
        ret = k
    else:
        ret = a
    k = k - a

k = k - b

if k > 0:
    if c > k:
        ret = ret - k
    else:
        ret = ret - c

print("{}".format(ret))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[A,B,C,K] = [int(s) for s in input().rstrip().split(' ')]
ans = 0
if K <= A:
    ans = K
else:
    ans += A
    if K > A+B:
        ans -= K-A-B
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()

  #f_inf=float("inf")
  #MOD=10**9+7
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    a, b, c, k = 2, 1, 1, 3

  else:
    ##INPUT 
    #n = input()
    a, b, c, k = map(int, input().split())

  ## SUBMITION CODES HERE
  if k <= a:
    print(k)
 
  elif k <= a+b:
    print(a)
 
  elif k > a+b:
    print(a-(k-(a+b)))  

main()

Submission status: Accepted

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

ans = min(A,K)
K -= A

K -= B

ans -= max(min(C,K),0)

print(ans)

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

Submission status: Accepted

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


def actual(a, b, c, k):
    if a >= k:
        return k
    else:
        k -= a

    if b >= k:
        return a
    else:
        k -= b

    return a - k


print(actual(a, b, c, k))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K = (int(x) for x in input().split())
if K>A:
    point = A
    Rest  = K-A
    if Rest>B:
        Rest  = Rest-B
        point = point+(-1)*Rest
else:
    point = K
print(point)

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

if K - (A + B) > 0:
    # C を取る
    score = A - (K - (A + B))
else:
    # C を取らない
    score = min(K, A)

print(score)