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())
pa = min([a, k])
k -= pa
pb = min([b, k])
k -= pb
pc = min([c, k])
print(pa - pc)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools

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 itertools
import math
import fractions
import functools

a, b, c, k = map(int, input().split())
sum = 0
if k <= a:
    print(k)
    quit()
else:
    sum = a
    k -= a
if k <= b:
    print(sum)
    quit()
else:
    k -= b
print(sum-k)

Submission status: Accepted

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

import sys

input = iter(sys.stdin.readlines()).next

def main():
   A, B, C, K = map(int, input().split())
   res = 0
   if A >= K:
      res = 1*K
   else:
      res += A
      K -= A
      if B >= K:
         res += 0*K
      else:
         res += 0*B
         K -= B
         res += -1*K

   print(res)

   return 0

if __name__ == '__main__':
   sys.setrecursionlimit(10000)
   main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if A - K >= 0:
    print(K)
elif A-K < 0 and A+B-K >= 0:
    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 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())
arr = [a,b,c]
ans = 0
for i,item in enumerate(arr):
  val = min(k,item)
  k-=val
  ans+=val*(1-i)
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:
import sys
input = sys.stdin.readline

A, B, C, K = map(int, input().rstrip().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)
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:
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	a, b, c, k = rli()
	ans = 0
	for add, cnt in [(1, a), (0, b), (-1, c)]:
		score = min(k, cnt)
		ans += add*score
		k -= score
		if k == 0:
			break
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

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

# check
result_score = 0
for score, i in [(1, A), (0, B), (-1, C)]:
        if K <= 0:
               continue

        if K >= i:
            result_score += score * i
            K -= i
        else:
            result_score += score * K
            K = 0

print(result_score)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(a+a+b-k if a<k else k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
 
A, B, C, K = map(int, sys.stdin.readline().split())
res = 0
res += min(A, K)
K -= A
if K > 0:
  K -= B
if K > 0:
  res -= min(C, K)
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #ここにコード
    #input
    A, B, C, K = map(int, input().split())

    #output
    #K <= Aの時
        #point = K
    #A < K <= A+Bの時
        #point = A
    # A+B < Kの時
        #point = A -{K-(A+B)}
    if K <= A:
        print(K)
    elif A < K <= A+B:
        print(A)
    elif K > A+B:
        print(2*A + B - K)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(score)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,_,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))
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
# B - Easy Linear Programming

a, b, c, k = map(int, input().split())
print(min(k, a, a + a + b - k))

Submission status: Accepted

Solution code:
#Solver:Rute
a,b,c,k = map(int,input().split())
if k<=a:
  print(k)
elif a<k<a+b:
  print(k)
else:
  #-1のカードの枚数超過 (k-(a+b))枚
  print(a-(k-(a+b)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#coding :utf-8

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sum = 0

X_a = min(A,K)
sum += X_a
K -= X_a

X_b = min(B,K)
K -= X_b

X_c = min(C,K)
sum -= X_c

print(sum)

Submission status: Accepted

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

ans = 0
x = min(k , a)
ans += x
k2 = k - x
x2 = min(k2, b)
k3 = k2 - x2
x3 = min(k3, c)
ans -= k3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
cards = [b, a, c]
print(min(k, cards[1]) - max(k - cards[0] - cards[1], 0))

Submission status: Accepted

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

sum = 0

for i in range(3):
    if a[3] <= 0:
        break
    if a[i] >= a[3]:
        sum += (1 - i) * a[3]
    else:
        sum += (1 - i) * a[i]
    a[3] -= a[i]
        
print(sum)

Submission status: Accepted

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

sum = 0

if a[0] >= a[3]:
    sum += 1 * a[3]
else:
    sum += 1 * a[0]

a[3] -= a[0]
a[3] -= a[1]

if a[3] > 0:
    if a[2] > a[3]:
        sum += -1 * a[3]
    else:
        sum += -1 * a[2]

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#B
ABCK = input().split(' ')
A = int(ABCK[0]) ; B = int(ABCK[1]) ; C = int(ABCK[2])
K = int(ABCK[3])
if K <= A:
    print(K)
elif K <= (A + B):
    print(A)
else:
    print(A - (K - A - B))

Submission status: Accepted

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

# B - Easy Linear Programming
a, b, c, k = map(int, input().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

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

print(a - c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input()
b=a.split()

x1=int(b[0]) #1
x2=int(b[1]) #0
x3=int(b[2]) #-1
x4=int(b[3]) #k

if x4 <= x1:
	print(x4)

elif x4 <= x1+x2:
	print(x1)

else:
	print(x1-(x4-x1-x2))

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
if k <= a:
    ans = k
elif k <= 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(k, a) - max(0, k-a-b))

Submission status: Accepted

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

if 0 <= A and 0 <= B and 0 <= C:
    if 1 <= K and K <= A + B + C <= 2 * (10 ** 9):
        if min(A, K) == A:
            result = A
            K -= A
        else:
            result = K
            K = 0
        if K > 0:
            K -= B
        if K > 0:
            result -= K

print(result)

Submission status: Accepted

Solution code:

#a,b=(int(x) for x in input().split()) #数値の時




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

if(k<=a):
  print(k)
else:
  sum=a
  t=k-a
  if(t<=b):
    print(sum)
    
  else:
    t-=b
    
    
    print(sum-t)

Submission status: Accepted

Solution code:
if __name__ == '__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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Easy Linear Programming
def main():
    A, B, C, K = map(int, input().split())
    print(min(A, K) - max(0, K - A - B))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations


def li():
    return list(map(int, sys.stdin.readline().split()))


def num():
    return map(int, sys.stdin.readline().split())


def nu():
    return int(input())


def find_gcd(x, y):
    while (y):
        x, y = y, x % y
    return x


def lcm(x, y):
    gg = find_gcd(x, y)
    return (x * y // gg)


mm = 1000000007

def solve():
    t = 1
    for tt in range(t):
        a,b,c,d=num()
        if(a+b>=d):
            print(min(a,d))
        else:
            z=d-a-b
            print(a-z)

                 


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ans = min(a, k)
k -= a
k -= b
ans -= k if k > 0 else 0

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def int_input():
    return int(input())


def print_ans(string):
    print(string)
    exit()

def yes():
    print("Yes")
    exit()

def no():
    print("No")
    exit()

A,B,C,K=input_int_list()

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect

def main():
    a, b, c, k = map(int, input().split())
    ans = 0
    #print('a: %d, b: %d, c: %d, k: %d, ans: %d' % (a, b, c, k, ans))
    if a <= k:
        ans += a
        k -= a
        a = 0
    else:
        a -= k
        ans += k
        k = 0
    #print('a: %d, b: %d, c: %d, k: %d, ans: %d' % (a, b, c, k, ans))
    if b <= k:
        k -= b
    else:
        b -= k
        k = 0
    #print('a: %d, b: %d, c: %d, k: %d, ans: %d' % (a, b, c, k, ans))
    if c <= k:
        ans += -c
        k -= c
        c = 0
    else:
        c -= k
        ans -= k
        k = 0
    #print('a: %d, b: %d, c: %d, k: %d, ans: %d' % (a, b, c, k, ans))
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

xa = min(K,A)
K -= xa
xb = min(K,B)
K -= xb


ans = xa - K
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

rest = K

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

Submission status: Accepted

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

xa = min(A,K)
K -= xa
xb = min(B,K)
K -= xb
xc = min(C,K)

print(xa-xc)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

#標準入力で受け取り配列に入れる
num_line = input().split()

#配列から変数を取り出す
num_one = int(num_line[0])
num_zero = int(num_line[1])
num_mini = int(num_line[2])
num_amount = int(num_line[3])

#num_oneから順に取っていく
if num_one >= num_amount:
    print(num_amount)
elif num_one + num_zero >= num_amount:
    print(num_one)
else:
    #マイナスの数を計算して保存
    minus_count = num_amount - (num_one + num_zero)
    print(num_one - minus_count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
sum1 = 0
while(k>0):
    if(k>=a and a!=0):
        k = k-a
        sum1+=a
        a=0
    elif(k<a):
        a = a - k
        sum1 += k
        k = k-k
    
    elif(k>=b and b!=0):
        k = k-b
        b=0
    elif(k<b):
        b = b - k
        k = k-k
    
    elif(k>=c and c!=0):
        k = k-c
        sum1 = sum1 - c
        c=0
    elif(k<c):
        c  = c-k
        sum1 = sum1 - k
        k = k-k

print(sum1)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
sum1 = 0
while(k>0):
    if(k>=a and a!=0):
        k = k-a
        sum1+=a
        a=0
    elif(k<a):
        a = a - k
        sum1 += k
        k = k-k
    
    elif(k>=b and b!=0):
        k = k-b
        b=0
    elif(k<b):
        b = b - k
        k = k-k
    
    elif(k>=c and c!=0):
        k = k-c
        sum1 = sum1 - c
        c=0
    elif(k<c):
        c  = c-k
        sum1 = sum1 - k
        k = k-k

print(sum1)

Submission status: Accepted

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

Submission status: Accepted

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

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 = list(map(int,input().split()))
one = a[0]
zero = a[1]
mone = a[2]
num = a[3]
 
ans = 0
if one >= num:
    print(num)
else:
    ans += one
    num -= one
    if zero >= num:
        print(ans)
    else:
        num -= zero
        print(one - num)

Submission status: Accepted

Solution code:
def main(a, b, c, k):
    total = 0

    a_k_min = min(a, k)
    total += a_k_min
    k -= a_k_min

    if k == 0:
        return total

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

    if k == 0:
        return total

    c_k_min = min(c, k)
    return total - c_k_min


if __name__ == '__main__':
    a, b, c, k = tuple(map(int, input().split(' ')))
    print(main(a, b, c, k))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

x = 0
n = min(A,K)
K -= n
x += n
n = min(B,K)
K -= n
x -= K

print(x)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

else:
	print(A - (K - (A + B)))

Submission status: Accepted

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

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

print(a-c)

Submission status: Accepted

Solution code:
a = input().split()

pura = int(a[0])     #1
zero = int(a[1])     #0
mai  = int(a[2])     #-1
num  = int(a[3])     #枚数
total = 0
k = num-pura-zero

if pura >= num:
    total = num
else:
    total = pura
    if zero >= num - pura:
        total = pura
    else:
        total = pura-(k)
print(total)

Submission status: Accepted

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


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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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 a >= k:
    print(k)
    exit()

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

print(a-(k-a-b))

Submission status: Accepted

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

Submission status: Accepted

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

if S[0] + S[1] + S[2] > 2 * 10 ** 9:
    print('Error')
elif S[0] >= S[3]:
    print(S[3])
elif S[3] > S[0] and S[3] <= S[0] + S[1]:
    print(S[0])
elif S[3] > S[0] + S[1] and S[3] <= S[0] + S[1] + S[2]:
    print(-1 * (S[3] - S[0] - S[1]) + S[0])
else:
    print('Error')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# 1 2 3 4

s = 0
if A < K:
    s += A
    if A + B < K:
        s += (K - (A + B)) * -1
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 b == 0:
        nc = k - a
        print( a - nc )
    elif b != 0:
        nb = k - a
        if nb <= b:
            print( a )
        elif nb > b:
            nc = nb - b
            print( a - nc )

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:
X = input().split()
A = int(X[0])
B = int(X[1])
C = int(X[2])
K = int(X[3])

d = 0

if K < A:
	d = K

elif K <= A + B:
	d = A

else:
	K = K - A - B
	d = A - K

print(d)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p,z,n,k = map(int,input().split())
print(min(k,p) if k<=(p+z) else p-(k - (p+z)))

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

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 = map(int,input().split())
print(min(K,A) - max(0,K-A-B))

Submission status: Accepted

Solution code:
from math import sqrt

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

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = (int(i) for i in input().split())
    xa = min(a, k)
    k -= xa
    xb = min(b, k)
    k -= xb
    xc = k
    ans = xa - xc
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
paramA, paramB, paramC, paramK = list(map(lambda x: int(x), input().split(' ')))

result = min(paramA, paramK)
paramK -= paramA
paramK -= paramB
if paramK > 0:
    result -= min(paramC, paramK)

print(result)

Submission status: Accepted

Solution code:
one, zero, dif_one,num = map(int,input().split())
if num <= one:
  print(num)
elif num <= one + zero:
  print(one)
else:
  print(one-(num-one-zero))

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,K=map(int, raw_input().split())
if 0<=K<=A:
    print min(K,A)
elif A<K<=A+B:
    print A
elif A+B<K:
    print A-min(C,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:
def main():
    A, B, C, K = map(int, input().split())
    ans = min(K, A) - min(max(0, K - A - B), C)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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


if  k <= a:
    print(k)
elif 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)
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
f=True
if(k>a):
    sum+=a
    k-=a
else:
    sum=k
    f=False
if (f):    
    k=k-b
    if(k<0):
        f=False
    if (f):
        sum-=(min(k,c))
print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

aa = min(a,k)
bb = min(b,k - aa)
cc = min(c,k - aa - bb)

print(aa - cc)

Submission status: Accepted

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

Submission status: Accepted

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