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: Time Limit Exceeded

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

while k>0:
  #print('kは' + str(k))
  if a > 0:
    a = a-1
    ans = ans + 1
   # print('aは' + str(a))
  elif b > 0:
    b = b-1
    ans = ans + 0
    #print('bは' + str(b))
  elif c > 0:
    c = c-1
    ans = ans -1
  k = k-1
  #print(k)
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0

if a <= k:
    cnt = cnt + 1*a #1
    k = k - a #3
elif a > k:
    for i in range(0, k):
        cnt += 1
        k -= 1

if b <= k:
    k = k - b #1
elif b > k:
    for i in range(0, k):
        k -= 1

if c <= k:
    cnt = cnt + -1*c
    k = k - c
elif c > k:
    for i in range(0, k):
        cnt += -1
        k -= 1

print(cnt)

Submission status: Time Limit Exceeded

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

cnt_a = 0
cnt_b = 0
cnt_c = 0

while k != 0:
    if a > 0:
        cnt_a += 1
        a -= 1
        k -= 1
    elif b > 0:
        cnt_b += 1
        b -= 1
        k -= 1
    else:
        cnt_c += 1
        c -= 1
        k -= 1

result = cnt_a * 1 + cnt_b * 0 + cnt_c * (-1)
print(result)

Submission status: Time Limit Exceeded

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

suma = 0

for i in range(k):
    if a == 0 and b == 0:
        suma = suma - k
        break
    elif a == 0 and c == 0:
        break
    elif b == 0 and c == 0:
        suma = suma + k
        break
    if a > 0:
        a = a - 1
        k = k - 1
        suma += 1
    elif b > 0:
        b = b - 1
        k = k - 1
    elif c > 0:
        c = c - 1
        k = k - 1
        suma -= 1
print(suma)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
temp = None
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if (a + b + c == K):
                if (temp is None):
                    temp = a - c
                else:
                    if (temp < a - c):
                        temp = a - c
print(temp)

Submission status: Time Limit Exceeded

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

sums = 0

for i in range(a):
    sums += 1
    k -= 1
    if k == 0:
        print(sums)

for i in range(b):
    sums += 0
    k -= 1
    if k == 0:
        print(sums)

for i in range(c):
    sums += -1
    k -= 1
    if k == 0:
        print(sums)

Submission status: Time Limit Exceeded

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

a,b,c,k = map(int, input().split())
p = 0
for i in range(k):
    if i+1 <= a:
        p += 1
    elif a < i+1 <= a + b:
        p += 0
    else:
        p -= 1

print(p)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int, input().split())
ans = 0
l = [a,b,c]
while k>0:
    if k < a:
        ans=k
        break
    else:
        ans += a 
        k-=a  
        a-=a 
    if k ==0:
        break    
    if k > b:
        k-=b
        b-=b
    else:
        k-=k
        b-=k    
    if k ==0:
        break    
    if k < c:
        ans += -k 
        k-=k
        break
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
L = list(map(int, input().split()))
maxres = 0

for i in range(3):
    n = [1, 0, -1]
    if L[i] <= L[3]:
        maxres += L[i] * n[i]
        L[3] -= L[i]
    else:
        for j in range(L[3]):
            maxres += n[i]
            L[3] -= 1
print(maxres)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int, input().split())
ans = 0
l = [a,b,c]
while k>0:
    if k < a:
        ans=k
        break
    else:
        ans += a 
        k-=a  
        a-=a 
    if k > b:
        k-=b
        b-=b
    else:
        k-=k
        b-=k    
    if k ==0:
        break    
    if k < c:
        ans += -k 
        k-=k
        break
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
S = {'A': 1, 'B': 0, 'C': -1}
M = {'A': 0, 'B': 0, 'C': 0}
while K > 0:
    if A > 0:
        K -= 1
        A -= 1
        M['A'] += 1
    elif B > 0:
        K -= 1
        B -= 1
        M['B'] += 1
    elif C > 0:
        K -= 1
        C -= 1
        M['C'] += 1

ans = S["A"]*M["A"] + S["B"]*M["B"] + S["C"]*M["C"]
print(ans)

Submission status: Time Limit Exceeded

Solution code:

abck = list(map(int, input().split()))

a = abck[0]
b = abck[1]
c = abck[2]
k = abck[3]

numbers = list()

for i in range(a):
    numbers.append(1)
for i in range(b):
    numbers.append(0)
for i in range(c):
    numbers.append(-1)

value = list()
value = numbers[0 : k]

print(sum(value))

Submission status: Time Limit Exceeded

Solution code:
import sys


def test():
    A, B, C, K = map(int, input().split())
    ans = 0
    for _ in range(K):
        if A > 0:
            ans += 1
            A -= 1
        elif B > 0:
            B -= 1
        elif C > 0:
            ans -= 1
            C -= 1
        else:
            break
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Time Limit Exceeded

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

for i in range(num):
    if pura > 0:
        pura = pura - 1
        total = total + 1
    elif zero > 0:
        zero = zero - 1
        total = total + 0
    elif mai > 0:
        mai = mai - 1
        total = total - 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
inputs = [int(x) for x in input().split()]
sumAns = 0

while(inputs[3] > 0):
	if inputs[0] > 0:
		sumAns = sumAns + 1
		inputs[0] = inputs[0] - 1
		inputs[3] = inputs[3] - 1
	elif inputs[1] > 0:
		inputs[1] = inputs[1] - 1
		inputs[3] = inputs[3] - 1
	elif inputs[2] > 0:
		sumAns = sumAns - 1
		inputs[2] = inputs[2] -1
		inputs[3] = inputs[3] - 1
print(sumAns)

Submission status: Time Limit Exceeded

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

wa = 0
wa += A
nokori = K - A - B

while nokori != 0:
    if C != 0:
        wa -= 1
        C -= 1
        nokori -= 1
    else:
        break

print(wa)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

g = 0

for i in range(d):
    if a > 0:
        g += 1
        a -= 1
        continue
    if b > 0:
        b -= 1
        continue
    if c > 0:
        g -= 1
        c -= 1
        continue

print(str(g))

Submission status: Time Limit Exceeded

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

sum=0
for i in range(K):
    if A>0:
        sum+=1
        A-=1
    elif B>0:
        B-=1
    elif C>0:
        sum-=1
        
print(sum)

Submission status: Time Limit Exceeded

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

l = []
i = 0
j = 0
s = 0
while i < a:
    l.append(1)
    i += 1
while j < b:
    l.append(0)
    j += 1
while s < c:
    l.append(-1)
    s += 1

print(sum(l[0:k]))

Submission status: Time Limit Exceeded

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

score = 0

for i in range(K):
    if A > 0:
        score = score + 1
        A = A - 1
    elif B > 0:
        score = score
        B = B - 1
    else:
        score = score - 1
        C = C - 1

print(score)

Submission status: Time Limit Exceeded

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

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

g = 0

while 0 == d:
    d = d - a * d
    if a - d >= 0:
        g += d
        d = 0

b > 0

for i in range(d):
    if a > 0:
        g += 1
        a -= 1
        continue
    if b > 0:
        b -= 1
        continue
    if c > 0:
        g -= 1
        c -= 1
        continue

print(str(g))

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int,input().split())
output = 0
m = 0
if B == 0 and C == 0 :
    print(A)
else :
    for i in range(A) :
        if m >= K :
            break
        output += 1
        m += 1
    for i in range(B) :
        if m >= K :
            break
        output += 0
        m+=1
    for i in range(C) :
        if m >= K :
            break
        output -= 1
        m+=1
    print(output)

Submission status: Time Limit Exceeded

Solution code:
import sys
a, b, c, k = map(int, input().split())
max = 0
if a < k:
    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)
                    sys.exit()
else:
    for i in range(k, -1, -1):
        for j in range(b, -1, -1):
            for l in range(c+1):
                if i+j+l == k:
                    print(i-l)
                    sys.exit()

Submission status: Time Limit Exceeded

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

while True:
    nokori=K
    maisu1=0
    maisu2=0
    maisu3=0
    if A<=nokori:
        maisu1=A
        nokori=nokori-maisu1
    else:
        maisu1=nokori
        break

    if B<=nokori:
        maisu2=B
        nokori=nokori-maisu2
    else:
        maisu2=nokori
        break
    
    maisu3=nokori

print(maisu1-maisu3)

Submission status: Time Limit Exceeded

Solution code:
t = list(map(int,input().split()))
ans = 0
for i in range (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: Time Limit Exceeded

Solution code:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
resultList = []
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if (a + b + c == K):
                resultList.append(a - c)
print(max(resultList))

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
ABC_total = 0
ABC_list =[]
for i in range(A):
  ABC_list.append(1)
for i in range(B):
  ABC_list.append(0)
for i in range(C):
  ABC_list.append(-1)
for i in range(K):
  ABC_total += ABC_list[i]
print(ABC_total)

Submission status: Time Limit Exceeded

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

newlist = []

for i in range(a):
  newlist.append(1)
for i in range(b):
  newlist.append(0)
for i in range(c):
  newlist.append(-1)
  
ans = 0
for i in range(k):
  ans = ans + newlist[i]
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = list(map(int, input().split())) 
l = []
for i in range(A):
  l.append(1)
for i in range(B):
  l.append(0)
for i in range(C):
  l.append(-1)
  
import itertools
m = 0
for i in itertools.combinations(l,K):
  if sum(i) > m:
    m=sum(i)
    
print(m)

Submission status: Time Limit Exceeded

Solution code:
list=list(map(int, input().split()))
A=list[0]
B=list[1]
C=list[2]
K=list[3]
ls=[]
for a in range(A+1):
    sum=0
    for b in range(K-a+1):
        c=K-a-b
        if b<=B and c<=C:
            sum=a-c
            ls.append(sum)
        else:
            continue
print(max(ls))

Submission status: Time Limit Exceeded

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

sum_max = 0

for i in range(K):
    if A:
        sum_max += 1
        A -= 1
    elif B:
        B -= 1
    else:
        sum_max -= 1
        C -= 1

print(sum_max)

Submission status: Time Limit Exceeded

Solution code:
import sys
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)
                sys.exit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
text_list = input().split()
n = 0
a = int(text_list[0])
b = int(text_list[0]) + int(text_list[1])
c = int(text_list[0]) + int(text_list[1]) + int(text_list[2])
for i in range(int(text_list[3])):
    if i < a:
        n += 1
    elif i < b:
        continue
    elif i < c:
        n -= 1

print(n)

Submission status: Time Limit Exceeded

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

while k > 0:
    if a > 0:
        a -= 1
        sum += 1
    elif b > 0:
        b -= 1
    elif c > 0:
        c -= 1
        sum -= 1
    k -= 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
text_list = input().split()
n = 0
a = int(text_list[0])
b = int(text_list[0]) + int(text_list[1])
c = int(text_list[0]) + int(text_list[1]) + int(text_list[2])
for i in range(int(text_list[3])):
    if i < int(text_list[0]):
        n += 1
    elif i < int(text_list[0]) + int(text_list[1]):
        continue
    elif i < int(text_list[0]) + int(text_list[1]) + int(text_list[2]):
        n -= 1

print(n)

Submission status: Time Limit Exceeded

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

res = 0
i = 0

a_times = 0
b_times = 0
c_times = 0

if a == k:
    a_times = k
else:
    for i in range(k):
        # print('i = ', i)
        if i < a:
            a_times += 1
            # print('res + 1= ', res)
        elif i + a < a + b:
            b_times += 1
            # print('res + 0 = ', res)
        elif i + a + b < a + b + c:
            c_times += 1
            # print('res - 1 = ', res)

print(a_times * 1 + b_times * 0 + c_times * -1)

Submission status: Time Limit Exceeded

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

if a>0 and k>0 and a<=k:
  k=k-a
  ans=ans+a
elif a>0 and k>0 and a>k:
  ans=ans+k
  k=0

while b>0 and k>0:
  b+=-1
  k+=-1

while c>0 and k>0:
  ans+=-1
  c+=-1
  k+=-1
  
print(ans)

Submission status: Time Limit Exceeded

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

sum = 0
num = 0
nm = [1,0,-1]

c = 0

while True:
    if n[num] == 0:
        num += 1
        continue
    sum += nm[num]
    n[num]-=1
    c+=1
    if c == n[3]:
        break


print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import itertools
A,B,C,K = map(int,input().split())

count=0
if A>=K:
    ans=K
else:
    count+=A
    if A+B>=K:
        ans=A

    else:
        for i in range(K-(A+B)):
            count-=(K-(A+B))
            ans=count

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, input().split())
li_card = []
for i in range(a):
  li_card.append(1)
for i in range(b):
  li_card.append(0)
for i in range(c):
  li_card.append(-1)

li_select = li_card[0:k]

print(sum(li_select))

Submission status: Time Limit Exceeded

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

for i in range(k):
    if a > 0:
        a-=1
        ans+=1
    elif b > 0:
        b-=1
    else:
        ans-=1

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(k):
    if a > 0:
        ans += 1
        a -= 1

    elif b > 0:
        b -= 1

    elif c > 0:
        ans -= 1
        c -= 1
    else:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
text_list = input().split()
n = 0
for i in range(int(text_list[3])):
  if i < int(text_list[0]):
    n += 1
  elif i < int(text_list[0]) + int(text_list[1]):
    pass
  elif i < int(text_list[0]) + int(text_list[1]) + int(text_list[2]):
    n -= 1
    
print(n)

Submission status: Time Limit Exceeded

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

ans = 0

while K > 0 and A > 0:
    ans += 1
    A -= 1
    K -= 1
    
while K > 0 and B > 0:
    ans += 0
    B -= 1
    K -= 1

while K > 0 and C > 0:
    ans += -1
    C -= 1
    K -= 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=map(int,input().split())
ct = 0
result = 0
while k>ct and a>0:
    result=result+1
    a=a-1
    ct=ct+1
while k>ct and b>0:
    b=b-1
    ct=ct+1
while k>ct and c>0:
    c=c-1
    result=result-1
    ct=ct+1

print(result)

Submission status: Time Limit Exceeded

Solution code:
A, B,C,K = map(int, input().split())
ans = 0
for i in range(K):
  if(i+1<=A):
    ans = ans + 1
  elif(i+1<=A+B):
    ans = ans +0
  elif(i+1<=A+B+C):
     ans = ans -1
  #print(ans)
        
        


print(ans)

Submission status: Time Limit Exceeded

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

A=[1 for x in range(A)]
B=[0 for x in range(B)]
C=[-1 for x in range(C)]
D=A+B+C

print(sum(D[:K]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int,input().split())
lst = []
m = 0
for i in range(A) :
    if m >= K :
        break
    lst.append(1)
    m += 1
for i in range(B) :
    if m >= K :
        break
    lst.append(0)
    m+=1
for i in range(C) :
    if m >= K :
        break
    lst.append(-1)
    m+=1
print(sum(lst))

Submission status: Time Limit Exceeded

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

for i in range(k):
  if(a != 0):
    ans += 1
    a -= 1
  elif(b != 0):
    b -= 1
  else:
    ans -= 1
    c -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

def xyz(a,b,c,k):
    if k==a:
        return(k)
    arr=[]
    for i in range(a):
        arr.append(1)
    for i in range(b):
        arr.append(0)
    for i in range(c):
        arr.append(-1)
    res=list(it.combinations(arr,k))
    re=[]
    for i in res:
        re.append(sum(i))
    return(max(re))


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

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K=map(int,input().split())
n=0
while A>0 and K>0:
  K-=1
  A-=1
  n+=1
while B>0 and K>0:
  K-=1
  B-=1
while C>0 and K>0:
  K-=1
  C-=1
  n-=1
print(n)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(k):
    if i+1 <= a:
        ans = ans + 1

    if i+1 > a + b:
        ans = ans -1

print(ans)

Submission status: Time Limit Exceeded

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

if a == d:
    print(a)
else:
    for _ in range(a):
        ans += 1
    
    if d-a != 0:
        for _ in range(d-a):
            ans += 0

    if d-a-b != 0:
        for _ in range(d-a-b):
            ans += -1
    
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
abcd = list(map(int,input().split()))
x = []
for i in range(abcd[0]):
    x.append(1)
for i in range(abcd[1]):
    x.append(0)
for i in range(abcd[2]):
    x.append(-1)
num = 0
for i in range(abcd[3]):
    num += x[i]
print(num)

Submission status: Time Limit Exceeded

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

if A > K:
    a = K
else:
    a = A
    
if (A + B) < K:
    for i in range(0,K-A-B):
        a = a - 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():
    A, B, C, K = map(int, input().split())
    nums = []
    for _ in range(A):
        nums.append(1)
    for _ in range(B):
        nums.append(0)
    for _ in range(C):
        nums.append(-1)
    nums.sort(reverse=True)
    print(sum(nums[:K]))
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int, input().split())
count = 0
ans = 0
while(count < K):
    for i in range(A):
        if (count == K):
            break
        ans += 1
        count += 1

        #print("A")
    for i in range(B):
        if (count == K):
            break
        count += 1
        #print("B")
    for i in range(C):
        if (count == K):
            break
        ans -= 1
        count += 1
        #print("C")

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(K):
	if A > 0:
		sum += 1
		A -= 1
	elif B > 0:
		B -= 1
	else:
		sum -= 1
		C -= 1

print(sum)

Submission status: Time Limit Exceeded

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

count = 0

while(k > 0):
  if a > 0:
    count += 1
    a -= 1
    k -= 1
  elif b > 0 :
    b -= 1
    k -= 1
  elif c > 0:
    count -= 1
    c -= 1
    k -= 1
  else:
    k -= 0
    
print(count)

Submission status: Time Limit Exceeded

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

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

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


for i in range(k):
    count -= 1

print(count)

Submission status: Time Limit Exceeded

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

res = 0

if a > 0:
    if a <= k:
        res += a
        k -= a
    elif a > k:
        while k > 0:
            res += 1
            k -= 1

if k > 0 and b > 0:
    if b <= k:
        k -= b
    elif b > k:
        k = 0

if k > 0 and c > 0:
    if c <= k:
        res -= c
        k -= c
    elif c > k:
        while k > 0:
            res -= 1
            k -= 1

print(res)

Submission status: Time Limit Exceeded

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

max = 0
for i in range(A):
    max+=1
    K-=1
    if K ==0:
        break
        

if not K==0:
    for j in range(B):
        max+=0
        K-=1
        if K ==0:
            break
    
if not K==0:
    for k in range(C):
        max-=1
        K-=1
        if K ==0:
            break
    
print(max)

Submission status: Time Limit Exceeded

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

nmax = -1 * K 

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a + b + c != K:
                continue
                
            nmax = max(nmax, a-c)
            
            
print(nmax)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


result = 0
for i in range(k):
    # print(result,a,b,c)2
    if a ==0:
        if b== 0:
            if c == 0:
             break
            result -= 1
            continue
        result += 0
        b -= 1
        continue
    result +=1 
    a -= 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int,input().split())
result = 0
#A分引く
if (K - A) < 0:
    for i in range(A):
        if K <= 0:
            break
        result = result + 1
        K  -= 1
else:
    K -= A
    result += 1*A

if (K-B) < 0:
    for i in range(B):
        if K <= 0:
            break
        K -= 1
else:
    K -= B

if (K-C) < 0:
    for i in range(C):
        if K <= 0:
            break
        K -= 1
        result -= 1
else:
    K -= C
    result -= C
print(result)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K= input().split()
a = int(A)
b = int(B)
c = int(C)
k = int(K)
n = 0
for i in range(k):
  if a >=i+1:
    n += 1
  elif a+b >= i+1:
    n += 0
  elif a + b + c >= i+1:
    n -= 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, input().split())
A = [1 for _ in range(a)]
B = [0 for _ in range(b)]
C = [-1 for _ in range(c)]
D = A + B + C
print(sum(D[:k]))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
a,b,c,k = map(int, input().split())
sum = 0
if b == 0 and c == 0:
    print(k)
else:
    for i in range(k):
        if a > 0:
           sum = sum + 1
           a = a - 1
        elif b > 0:
            b = b - 1
        elif c > 0:
            sum = sum - 1
            c = c - 1
    print(sum)

Submission status: Time Limit Exceeded

Solution code:
a1,b0,cn1,d=map(int,input().split())
Output = 0

for i in range(d):
  if i < a1:
    Output = Output + 1
  elif i < a1+b0:
    pass
  else:
    Output = Output - 1  
print(Output)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


result = 0

for i in range(k):
    if a > 0:
        a = a-1
        result += 1

    elif b > 0:
        b = b-1
        result += 0

    else:
        result -= 1


print(result)

Submission status: Time Limit Exceeded

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

while k > 0:
    if a > 0:
        result+=1
        a-=1
        k-=1
        continue
    elif b > 0:
        b-=1
        k-=1
        continue
    else:
        result-=1
        c-=1
        k-=1
        continue

print(result)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = input().strip().split()
A, B, C, K = [int(A), int(B), int(C), int(K)]
sum = 0

for i in range(K):
	if A > 0:
		sum += 1
		A -= 1
	elif B > 0:
		B -= 1
	elif C > 0:
		sum -= 1
		C -= 1

print(sum)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(k):
    if a > 0:
        ans += 1
        a -= 1

    elif b > 0:
        b -= 1

    elif c > 0:
        ans -= 1
        c -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

array = [1, 0, -1]


ans = 0
for i in range(K):
    if(i<A):
        ans += array[0]
    elif(i<A+B):
        ans += array[1]
    else:
        ans += array[2]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, input().split())
A = [1 for _ in range(a)]
B = [0 for _ in range(b)]
C = [-1 for _ in range(c)]
D = A + B + C
p = 0
for i in range(k):
    p += D[i]
print(p)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(k):

    if a > 0:
        ans += 1
        a -= 1
        continue
    if b > 0:
        b -= 1
        continue
    if c > 0:
        ans -= 1
        c -= 1
        continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = input()
a = a.split()
c = 0
for d in range (0, len(a)):
    a[d] = int(a[d])
for b in range (0, a[3]):
    if a[0] > 0:
        c = c+1
        a[0] = a[0]-1
    elif a[1] > 0:
        a[1] = a[1]-1
    elif a[2] > 0:
        c = c -1
        a[2] = a[2]-1
print(c)

Submission status: Time Limit Exceeded

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



arr_a=[1 for i in range(a)] 
arr_b=[0 for i in range(b)]
arr_c=[-1 for i in range(c)]
arr=arr_a+arr_b+arr_c

print(sum(arr[:k]))

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
res = 0
total = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if K == a + b + c:
                total = a*1 + b*0 + c*-1
                if res < total:
                    res = total
print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, input().split())
box = []
result = 0

if c == 0:
    if a >= k:
        print(k)
    else:
        print(a)
    quit()

for i in range(a):
    box.append(1)
for i in range(b):
    box.append(0)
for i in range(c):
    box.append(-1)

for i in range(k):
    result = result + box[i]

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while a>0 and k>0:
  ans+=1
  a+=-1
  k+=-1

while b>0 and k>0:
  b+=-1
  k+=-1

while c>0 and k>0:
  ans+=-1
  c+=-1
  k+=-1
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int,input().split())
cnt = 0
sum = 0
for i in range(A):
  if cnt == K:
    print(sum)
    exit()
  sum = sum + 1
  cnt = cnt + 1
for j in range(B):
  if cnt == K:
    print(sum)
    exit()
  sum = sum + 0
  cnt = cnt + 1
for k in range(C):
  if cnt == K:
    print(sum)
    exit()
  sum = sum + (-1)
  cnt = cnt + 1

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
a,b,c,k=map(int,input().split())
s=[]
for _ in range(a):
    s.append(1)
for _ in range(b):
    s.append(0)
for _ in range(c):
    s.append(-1)
s_s=s[:k]
print(sum(s_s))

Submission status: Time Limit Exceeded

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

mycnt = 0
myans = 0

if A >= K:
    print(K)
    sys.exit()
else:    
    while mycnt < K:
        if A>0:
            mycnt += 1
            A -=1
            myans += 1
        elif B>0:
            mycnt += 1
            B -=1
        else:
            mycnt+=1
            myans -=1
print(myans)

Submission status: Time Limit Exceeded

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

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

while(k != 0):
    if a > 0:
        a -= 1
        sum += 1
    elif b > 0:
        b -= 1
    elif c > 0:
        c -= 1
        sum -= 1
    k -= 1

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

print(sum)

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

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

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