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: Wrong Answer

Solution code:
li = list(map(int,input().split()))
A = li[0]
B = li[1] 
C = li[2] 
K = li[3] 

if A >= K or A + B == K:
  print(str(A))
elif A + B < K:
  num = A - (K - A - B)
  print(str(num))

Submission status: Wrong Answer

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

if K <= A:
    score = A
elif K <=A+B:
    score = A+B
elif K <=A+B+C:
    score = A-(K-(A+B))

print(score)

Submission status: Wrong Answer

Solution code:
t = list(map(int,input().split()))
ans = 0
for i in range (1,t[3]):
  if t[0] != 0:
    ans += 1
    t[0] -= 1
  elif t[1] != 0:
    ans += 0
    t[1] -= 1
  elif t[2] != 0:
    ans -= 1
    t[2] -= 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s  = input().split(" ")
a  = int(s[0])
b  = int(s[1])
c  = int(s[2])
k  = int(s[3])
 
t = 0
if a >= k:
  print(a)
else:
  t += a
  if b >= (k - a):
    print(a)
  else:
    if c <= (k - a -b): 
    	t -=  c
    else:
      	t -= (k - a -b)
    print(t)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

if k <= a:
    ans = k

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

print(ans)

Submission status: Wrong Answer

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

if card[3] > card[0] + card[1]:
    x = card[3] - card[0] - card[1]
    print(card[0] + x * -1)
else:
    print(card[0])

Submission status: Wrong Answer

Solution code:
i = input()
a = int(i.split()[0])
b = int(i.split()[1])
c = int(i.split()[2])
k = int(i.split()[3])

count = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
dif = K - (A + B)
ans = 1 * A

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

Submission status: Wrong Answer

Solution code:
A,B,C,K = input().split(' ')
A = int(A) # 1
B = int(B) # 0
C = int(C) # -1
K = int(K)


# 1 x ?,  0 x ?,  -1 x ?
if (K <= A + B):
  print(A)
else:
  print(A + ((K - (A + B)) * -1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
lst = []
sum = 0
if A <= K:
    sum += 1 * A
else:
    sum += 1 * K

k = K - (A + B)

if C <= k:
    sum += -1 * C
else:
    sum += -1 * k

print(sum)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

def f(p, n, k, res):
    if k - n > 0:
        return k - n, p * (k - n) + res
    else:
        return 0, p * k + res


nokori, res = f(1, A, K, res)
nokori, res = f(0, B, K, res)
nokori, res = f(-1, C, K, res)
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 1 * A
K = K - A

if 0 < K:
    ans = ans + 0 * B
    K = K - B

if 0 < K:
    ans = ans + (-1) * K

print(ans)

Submission status: Wrong Answer

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

ab = a+b
abc = a+b+c
print(a,b,c,k)
if k <= ab:
  print(k)
else:
  print(a-(k-ab))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
result = A * 1
# Aを使った後の残が0より大きい
if K - A > 0:
    # Bを使った後の残が0より大きい
    if K - A - B > 0:
        result = result + (K - A - B) * -1
        print(result)
    # Bを使った後の残が0以下
    else:
        print(result)
# Aを使った後の残が0以下
else:
    print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

res = 0

if K < A:
    print(K)

res += A
K -= A

if K:
    K -= B

if K > 0:
    res -= K

print(res)

Submission status: Wrong Answer

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

total = 0
if k >= a:
    total += a
    k -= a
    if k == 0:
        pass
    elif k >= b:
        total += 0
        k -= b
        if k == 0:
            pass
        elif k >= c:
            total -= 1
        else:
            for i in range(k):
                total -= 1
    else:
        for i in range(k):
            total += 0
else:
    for i in range(k):
        total += 1
"""
for i in range(k):
    if a > 0:
        total += 1
        a -= 1
    elif b > 0:
        total += 0
        b -= 1
    elif c > 0:
        total -= 1
        c -= 1
"""
print(total)

Submission status: Wrong Answer

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

a = A * 1
b = B * 0
c = C * -1

print(a)

Submission status: Wrong Answer

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

if (a + b >= k or a == k) or (a == 0 and c == 0):
    print(a)
else:
    print(a + ((a+b) - k))

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
n = a[0]
m = a[1]
l = a[2]
k = a[3]

if n > k:
    print(n)
elif n + m > k:
    print(n)
else:
    print(n - l)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(K):
    Acnt += 1
    ans  += 1
    if i == A-1:
        break

K -= Acnt

for i in range(K):
    Bcnt +=1
    if i == B-1:
        break

K -= Bcnt

for i in range(K):
    Ccnt +=1
    ans -= 1
    if i == C-1:
        break

K -= Ccnt

print(ans)

Submission status: Wrong Answer

Solution code:
#--Easy Linear Programming

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

number = 0
count = 0
if (k < a):
    count = count + a
    print(count)
    exit()

if (k >= a):
    number = number + a
    count = count + a

kk = k - number

if (kk < b):
    print(count)
    exit()

if (kk >= b):
    number = number + b

kkk = k - number

if (kkk < c):
    count = count - kkk
    print(count)
    exit()

if (kkk >= c):
    count = count - c

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, k = map(int, input().split())
ans = 0
cnt = 0
if a <= k:
    ans += a*1
    cnt += a
if cnt <= k:
    cnt += b
if cnt <= k:
    ans += (-1)*(k-cnt)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 1

if k <= a:
    ans = k

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
plus, zero, minus, number = map(int, input().split(" "))

if(plus + zero >= number):
  print(plus)
else:
  print(plus - min(number - plus - zero, minus))

Submission status: Wrong Answer

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

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

    a = A if A<K else K
    b = (K-a) if (K-a)>=0 and (K-a)<B else B
    c = K-A-B if (K-A-B)<C else C
    print(a-c)


main()

Submission status: Wrong Answer

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

n_a = 0
n_b = 0
n_c = 0

n_a = A

if K-A >= B:
  n_b = B
  n_c = K-A-B
  
else:
  pass

print(n_a+(-1)*n_c)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

# 1 ✕ N
A, B, C, K = list(map(int, input().rstrip().split()))

ans = 0
array = [(A, 1), (B, 0), (C, -1)]

for k, v in array:
    if K > 0:
        n = min(A, K)
        ans += n * v
        K = K - n

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
sum = 0
for i in range(a+1):
    for j in range(b+1):
        if sum <= (1*i) + (-1*(k - i - j)):
            sum = (1*i) + (-1*(k - i - j))
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B,C,K=map(int,input().split())
U=0
E=0
D=0
U=A-K
E=K-A
D=K-E
if U>=0:
    print(K)
elif D>=0:
    print(D)
else:
    for i in range(0,C):
        D=D+-1
        
print(D)

Submission status: Wrong Answer

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

ans = 0
end_flag = False

if K >= A:
    ans += A

else:
    ans = K
    end_flag = True

if end_flag == False and K - A >= B:
    ans += 0

else:
    ans += 0
    end_flag = True

if end_flag == False and K - A - B >= C:
    ans += -C

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

print(ans)

Submission status: Wrong Answer

Solution code:
#--Easy Linear Programming

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

number = 0
count = 0
if (k <= a):
    count = count + a
    print(count)
    exit()

if (k > a):
    number = number + a
    count = count + a

kk = k - number

if (kk <= b):
    print(count)
    exit()

if (kk > b):
    number = number + b

kkk = k - number

if (kkk <= c):
    count = count - kkk
    print(count)
    exit()

if (kkk > c):
    count = count - c

print(count)

Submission status: Wrong Answer

Solution code:
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

a,b,c,k = NextInts()

ans = 0
ans += min(a,k)
k-=a
k-=b
ans -= min(k, c)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
max = 0
for i in range(a, -1, -1):
    for j in range(b, -1, -1):
        for l in range(c+1):
            if i+j+l == k:
                print(i-l)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
A = a[0]
B = a[1]
C = a[2]
K = a[3]
if A > K :
    print(A)
elif (A + B) > K:
    print(A)
else:
    print(A-(K-A-B))

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
res=0
na=min(a,k)
if na==a:
    res+=a
    k-=na
else:
    print(a)
    exit()
if a==k:
    print(a)
    exit()
if k == 0:
    print(res)
    exit()
nb=min(b,k)
if nb==b:
    k-=nb
else:
    print(a)
    exit()
if b==k:
    print(a)
    exit()
if k == 0:
    print(res)
    exit()
nc=min(c,k)
if nc==c:
    res-=c
    print(res)
    exit()
else:
    exit()
if c==k:
    res -= c
    print(res)
    exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = [int(x) for x in input().split()]
ans = 0
x[3] -= x[1]
if x[3] > 0:
    ans = x[0]
    x[3] -= x[0] + x[1]
    if x[3] >= 0:
        ans -= x[3]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))

t = inpl()
cnt = 0

if t[3] >= t[0]:
    t[3] -= t[0]
    cnt = t[0]
    if t[3] <= t[1]:
        pass
        t[3] -= t[1]
        cnt -= t[3]
    else:
        t[3] -= t[1]
        cnt -= t[3]
else:
    if t[3] <= t[0]:
        cnt = t[3]
    else:
        cnt = t[0]

print(cnt)

Submission status: Wrong Answer

Solution code:
s = input().split()
n = int(s[3])
sum_=0
i=1
while i < n:
    if int(s[0]) >= i:
        sum_+=1
    elif int(s[1]) >= i:
        sum_+=0
    else:
        sum_-=1
    i += 1
print(sum_)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
arr = list(input().split())
A=int(arr[0])
B=int(arr[1])
C=int(arr[2])
K=int(arr[3])

sum=0
sum+=A
K-=A
if K > 0:
	sum+=B
	if K > 0:
		sum-=K

print(sum)

Submission status: Wrong Answer

Solution code:
t = list(map(int,input().split()))
ans = 0
for i in range (1,t[3]):
  if t[1] != 0:
    ans += 1
    t[1] -= 1
  elif t[2] != 0:
    ans += 0
    t[2] -= 1
  elif t[3] != 0:
    ans -= 1
    t[3] -= 1
print(ans)

Submission status: Wrong Answer

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


tmp = k - a # k比a的張數多
tmp2 = k -a-b

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if A>=K:
    sum = A
    
elif A+B>=K:
    sum = A
    
else:
    sum = 2*A-K+B

print(sum)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if( A[0] >= A[3] ):
  print(A[0])
elif( A[0] + A[1] >= A[3] ):
  print(A[0])
else:
  p = A[0]
  m = A[3] - (A[0]+A[1])
  print(p-m)

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

ans=0
if A[0]<A[3]:
  ans = A[0]
else:
  ans = A[3]
  print(ans)
  
if A[3]-A[0]-A[1]>0:
  print(ans-(A[3]-A[0]-A[1]))
else:
  print(ans)

Submission status: Wrong Answer

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

max  = 0

if(a > k):
  max += k
  k = 0
else:
  max += a
  k -= a 
  
if(not k == 0)and(b > k):
  k = 0
else:
  k -= b
  
if(not k == 0)and(c > k):
  max -= k
else:
  max -= c

print(max)

Submission status: Wrong Answer

Solution code:
def q2():
    A, B, C, K = (int(i) for i in input().split())
    ans = 0

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

    #print(K)
    if K <= B:
        return ans
    else:
        K -= B

    #print(K)
    if K > C:
        ans -= C
        return ans
    else:
        ans -= K
        return ans


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    num_plus_one, num_zero, num_minus_one, total_num = map(int, input().split(' '))
    counter = 0

    if total_num < num_plus_one + num_zero:
        counter = num_plus_one
    elif total_num <= num_plus_one + num_zero + num_minus_one:
        counter = num_plus_one - (total_num - num_plus_one - num_zero)
    else:
        counter = num_plus_one - num_minus_one

    print(counter)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
a, b, c, k = map(int, input().split())
x = 0

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

Submission status: Wrong Answer

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

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

    a = A
    b = (K-a) if (K-a)>=0 and (K-a)<B else B
    c = K-A-B if (K-A-B)<C else C
    print(a-c)


main()

Submission status: Wrong Answer

Solution code:
def create_union_answer(a, b, c, k):
    if a >= k:
        return a
    if a + b >= k:
        return a
    # can select type[c] card numbers.
    can_c = k - (a + b)
    if can_c < 0:
        can_c = 0
    return a - can_c

values = input().split()

a = int(values[0])
b = int(values[1])
c = int(values[2])
k = int(values[3])

answer = create_union_answer(a, b, c, k)
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    diff = (a + b)
    r = (k - diff)
    res = a + (r * -1)
    print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    a,b,c,k=L()
    if a+b>=k:
        print(a)
    else:
        tmp=k-(a+b)
        print(a-tmp)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
print(A,B,C,K)
res = 0
for i in range(A+1):
  for j in range(B+1):
    ans = 1*i + 0*j + (-1)*(K-i-j)
    res = max(res,ans)
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
q = [a, b, c]
w = [1, 0, -1]
ans = 0
for i in range(3):
  try:
    t = min(k/w[i], q[i])
    t2 = t
  except ZeroDivisionError:
    t = b
    t2 = 0
  k -= t
  ans += t2
print(int(ans))

Submission status: Wrong Answer

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

if (a + b == k or a == k) or (a == 0 and c == 0):
    print(a)
else:
    print(a + ((a+b) - k))

Submission status: Wrong Answer

Solution code:
body_1,body_2,body_3,cards=map(int,input().split())
total=0
sa=cards-body_1-body_2
if body_1>=cards:
    total+=body_1
elif body_1<cards:
    if (body_1+body_2)>=cards:
        total+=body_1
    else:
        total=body_1-sa

print(total)

Submission status: Wrong Answer

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

if (D - A - B >= 0):
    ancer = 1 * A  + (-1 *(D - A - B))
else:
    ancer = 1 * A
print(ancer)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
A, B, C, K = map(int, input().split())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
a,b,c,k=map(int,input().split())
t=0
for i in range(a):
    t+=1
    for j in range(b):
        t+=0
        if a+b>=k:
            print(t)
            sys.exit()
        else:
            for p in range(k-a-b):
                t+=-1
                print(t)
                sys.exit()

Submission status: Wrong Answer

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

if K >= A:
    a = A
else:
    print(K)
    exit()
if A == 0 and C == 0:
    print(0)
    exit()

if A == 0 and B == 0:
    print(-1*K)
    exit()

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

print(a+c)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

A = a
B = 0
C = -1 * c

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

Submission status: Wrong Answer

Solution code:
A,B,C,N = map(int,input().split())
sum_card = [A,B,C]
for i in range(2):
    sum_card[i+1] += sum_card[i]
if(N-sum_card[1]<=0):
    print(A)
elif(N>=sum_card[2]):
    print(A-C)
else:
    print((N-sum_card[1])*(-1)+A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


tmp = k - a # k比a的張數多
tmp2 = k -a-b

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
t = list(map(int,input().split()))
ans = 0
for i in range (t[3]):
  if t[1] != 0:
    ans += 1
    t[1] -= 1
  elif t[2] != 0:
    ans += 0
    t[2] -= 1
  elif t[3] != 0:
    ans -= 1
    t[3] -= 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

info = input().split(' ')
card_one = int(info[0])
card_zero = int(info[1])
card_minus = int(info[2])
number = int(info[3])

sumnum = 0

if (number >= card_one):
    number = number - card_one
    sumnum = sumnum + card_one
else:
    print(card_one)
    sys.exit()

if (number >= card_zero):
    number = number - card_zero
else:
    print(sumnum)
    sys.exit()

if (number >= card_minus):
    sumnum = sumnum - card_minus
    print(sumnum)
else:
    sumnum = sumnum - number
    print(sumnum)

Submission status: Wrong Answer

Solution code:
"""
"""
A, B, C, K = map(int, input().split())
sum = 0
while K >= 1:
    if A >= 1:
        if K - A >= 0:
            sum += A
            A = 0
            K -= A
        else:
            sum += K
            K = 0
    elif B >= 1:
        if K - B >= 0:
            K -= B
        else:
            K = 0
    else:
        sum -= K
        K = 0

print(sum)

Submission status: Wrong Answer

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) * C)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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