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

score = 0

while K>0:
    if A>0:
        score += 1
        A-=1
        K-=1
    elif B>0:
        B-=1
        K-=1
    elif C>0:
        score -=1
        C-=1
        K-=1
    else:
        break
print(score)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=map(int,input().split())
ans=[]
for i in range(a+1):
    for j in range(b+1):
        ans.append(i+j*0-(k-i-j))
print(max(ans))

Submission status: Time Limit Exceeded

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

if A >= K:
    print(K)
else:
    for i in range(K):
        if A > (i + 1):
            result += 1
            continue
        elif A == (i + 1):
            result += 1
            continue

        if B > (i + 1 - A):
            result += 0
            continue
        elif B == (i + 1 - A):
            result += 0
            continue

        if C > (i + 1 - A - B):
            result -= 1
            continue
        elif C == (i + 1 - A - B):
            result -= 1
            break
        else:
            break
    print(result)

Submission status: Time Limit Exceeded

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

for i in range(K):
    if A > (i + 1):
        result += 1
        continue
    elif A == (i + 1):
        result += 1
        continue

    if B > (i + 1 - A):
        result += 0
        continue
    elif B == (i + 1 - A):
        result += 0
        continue

    if C > (i + 1 - A - B):
        result -= 1
        continue
    elif C == (i + 1 - A - B):
        result -= 1
        break
    else:
        break

print(result)

Submission status: Time Limit Exceeded

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

print(sum(nums[:k]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
one,zero,ng_one,card = map(int, input().split())

card_list = []
for i in range(one):
    card_list.append(1)
for i in range(zero):
    card_list.append(0)
for i in range(ng_one):
    card_list.append(-1)

print(sum(card_list[:card]))

Submission status: Time Limit Exceeded

Solution code:
one, zero, ng_one, card = map(int, input().split())

card_list = []
for i in range(one):
    card_list.append(1)
for i in range(zero):
    card_list.append(0)
for i in range(ng_one):
    card_list.append(-1)

print(sum(card_list[:card]))

Submission status: Time Limit Exceeded

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

for i in range(1, k+1):
    if a_num > 0:
        ans += 1
        a_num -= 1
    elif b_num > 0:
        b_num -= 1
    else:
        ans -= 1
        c_num -= 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
        continue
    if b != 0:
        ans += 0
        b += -1
        continue
    if c != 0:
        ans += -1
        c += -1
        continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
nums = [int(e) for e in input().split()]
abcs = [nums[0],nums[0]+nums[1],nums[0]+nums[1]+nums[2]]
max = 0
for k in range(nums[3]):
    if k<abcs[0]:
        max+=1
    elif k<abcs[1]:
        continue
    elif k<abcs[2]:
        max-=1
print(max)

Submission status: Time Limit Exceeded

Solution code:
in1 = input().split()
A,B,C,K = int(in1[0]),int(in1[1]),int(in1[2]),int(in1[3])
SUM = int(0)
for i in range(K):
    if A>0:
        SUM+=1
        A-=1
    elif B>0:
        SUM+=0
        B-=1
    elif C>0:
        SUM-=1
        C-=1
print(SUM)

Submission status: Time Limit Exceeded

Solution code:
in1 = input().split()
A,B,C,K = int(in1[0]),int(in1[1]),int(in1[2]),int(in1[3])
SUM = int(0)
for i in range(K):
    if A!=0:
        SUM+=1
        A-=1
    elif B!=0:
        SUM+=0
        B-=1
    elif C!=0:
        SUM-=1
        C-=1
print(SUM)

Submission status: Time Limit Exceeded

Solution code:
in1 = input().split()
A = int(in1[0])
B = int(in1[1])
C = int(in1[2])
K = int(in1[3])
SUM = int(0)
for i in range(K):
    if A>0:
        SUM+=1
        A-=1
    elif B>0:
        SUM+=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())

count = K
score = 0

if(0 <= A-K):
    print(K)

else:
    while(0 < count):
        if(0 < A):
            score += 1
            count -=1
            A -=1
        else:
            if(0 < B):
                count -= 1
                B -= 1
            else:
                score -=1
                count -=1

    print(score)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
'''
if the value of k is less than or equal to a => print out k*1

but if value of k is more than the value of a -> use as many of the b cards as available

If the value of k is still more, use the c cards

'''

def easy(a,b,c,k):
    print(k*1)

def hard(a,b,c,k):
    total= 0
    sum = 0

    while total <k:
        if a>0:
            sum+=1
            total+=1
            a = a-1

        elif b>0 and a<=0:
            sum = sum + 0
            total+=1
            b = b-1

        elif a<=0 and b<=0 and c>0:
            sum = sum - 1
            total += 1
            c = c-1


    print(sum)


userInput = input()

user_input_list = userInput.split()

a,b,c,k = [int(e) for e in user_input_list]

a = int(a)
b = int(b)
c = int(c)
k = int(k)

if k<=a:
    easy(a,b,c,k)

if k>=a:
    hard(a,b,c,k)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = input().split()
n = [int(i) for i in n]
num = n[-1]
count = 0
for i in range(num):
  num -= 1
  if n[0] is not 0:
    count+=1
    n[0] -= 1
  elif n[0] is 0 and n[1] is not 0:
    n[1] -= 1
  else:
    count-=1
    n[-2] -= 1

print(count)

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
  else:
    sum -= 1
    C -= 1

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

ans = 0

while True:
    flg = True

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

    if not flg:
        break

    for i in range(b):
        k -= 1
        if k == 0:
            flg = False
            break

    if not flg:
        break

    for i in range(c):
        ans += -1
        k -= 1
        if k == 0:
            flg = False
            break

    if not flg:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ones = [1 for i in range(a)]
zeros = [0 for i in range(b)]
minusOnes = [-1 for i in range(c)]

combination = np.array(ones + zeros + minusOnes)
sum = 0
for i in range(k):
    sum += combination[i]
print(sum)

Submission status: Time Limit Exceeded

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

total = 0

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

while k > 0 and c > 0:
    total -= 1
    c -= 1
    k -= 1

print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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 = NextIntList()
point = 0
while K>0:
	while A>0 and K>0:
		point+=1
		A-=1
		K-=1
	while B>0 and K>0:
		point+=0
		B-=1
		K-=1
	while C>0 and K>0:
		point-=1
		C-=1
		K-=1
print(point)

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,input().split()))
m=0
for i in range(a[3]):
    if a[0]>0:
        m+=1
        a[0]-=1
    elif a[1]>0:
        a[1]-=1
    elif a[2]>0:
        m-=1
        a[2]-=1

print(m)

Submission status: Time Limit Exceeded

Solution code:
n_1, n_0, n_m1, k = map(int, input().split())
sum_n = 0

for i in range(k):
  if n_1 != 0:
    sum_n += 1
    n_1 -=1
  elif n_0 != 0:
    n_0 -= 1
  else:
    sum_n -= 1

print(sum_n)

Submission status: Time Limit Exceeded

Solution code:
#python 3.7.1

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

cnt=0

while(d!=0):

  

  if(a!=0 and d>0):

    d-=1

    a=a-1

    

    cnt=cnt+1

    

  elif b!=0 and d>0:

    d-=1

    b=b-1

    

    

  elif c!=0 and d>0:

    d-=1

    c=c-1

    

    cnt=cnt-1

    

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int,input().split())
sum = 0
for i in range(K):
    if A > 0:
        sum += 1
        A -= 1
    elif B > 0:
        sum += 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())
li = [1 for a in range(A)]+ [ 0 for b in range(B)]+ [ -1 for c in range(C)]
print(sum(li[:K]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

A,B,C,K = MI()
ans = 0
while K>0:
    if A>0:
        ans+= 1
        A -= 1
    elif B>0:
        B -= 1
    else:
        ans -= 1
        C -= 1
    K -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

A,B,C,K = MI()
ans = 0
while K>0:
    if A:
        ans+= 1
        A -= 1
    elif B:
        B -= 1
    else:
        ans -= 1
        C -= 1
    K -= 1
print(ans)

Submission status: Time Limit Exceeded

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:
                break
        while K > 0 and i > 0:
                result_score += score
                i -= 1
                K -= 1

print(result_score)

Submission status: Time Limit Exceeded

Solution code:
# B - Easy Linear Programming

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

# check
result_score = 0
while K > 0:
        for score, i in [(1, A), (0, B), (-1, C)]:
                if K <= 0:
                        break
                while K > 0 and i > 0:
                        result_score += score
                        i -= 1
                        K -= 1

print(result_score)

Submission status: Time Limit Exceeded

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

# check
result_score = 0
while K > 0:
        for score, i in [(1, A), (0, B), (-1, C)]:
                while K > 0 and i > 0:
                        result_score += score
                        i -= 1
                        K -= 1

print(result_score)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())  # a 1 b 0 c -1

max_value = 0
m = 0
while(A>0):
    if m < K:
        max_value+=1
        m += 1
        A = A - 1
    else:
        break
        
while(B>0):
    if m < K:
        m += 1
        B = B - 1
    else:
        break
while(C>0):
    if m < K:
        max_value -= 1
        m += 1
        C = C - 1
    else:
        break
        

print(max_value)

Submission status: Time Limit Exceeded

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

num=[]

for i in range(int(b[0])):
	num.append(1)

for i in range(int(b[1])):
	num.append(0)

for i in range(int(b[2])):
	num.append(-1)

k=int(b[3])
print(sum(num[0:k]))

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
max_val = -1*C
cnt = 1
out = 0
while K >= cnt:
    if A < cnt:
        break
    out += 1
    cnt += 1

while K >= cnt:
    if B < cnt - A:
        break
    cnt += 1

while K >= cnt:
    cnt += 1
    out -= 1

print(out)

Submission status: Time Limit Exceeded

Solution code:
a=input().split()
b=[int(i) for i in a]
c=[]
for i in range(b[0]):
    c.append(1)
for i in range(b[1]):
    c.append(0)
for i in range(b[2]):
    c.append(-1)
print(sum(c[0:(b[3])]))

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 = ans + 1
    a = a - 1
  elif b > 0:
    b = b - 1
  else:
    ans = ans - 1
    c = c - 1

print(ans)

Submission status: Time Limit Exceeded

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

    ans = 0
    cnt = 0

    if A >= 1:
        if K >= A:
            cnt = A
        else:
            cnt = K

        for i in range(cnt):
            ans += 1

    tmp = K - A - B
    if tmp >= 1:
        cnt = tmp
        for i in range(cnt):
            ans -= 1

    print(f'{ans}')

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int,input().split())
s=0
sss=a+b+c
ss=a+b
for i in range(1,k+1):
    if i <= sss-b-c:
        s+=1
    elif i<=a+b:
        s+=0
    else:
        s-=1
print(s)

Submission status: Time Limit Exceeded

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

s=-1*K*C

lc=[]
lc_=[]
for i in range(A+1):
  for j in range(min(K-i+1,B+1)):
    lc.append([i,j,K-i-j])

#print(lc)

for i in range(len(lc)):
  if lc[i][0]<=A and lc[i][1]<=B and lc[i][2]<=C:
    # print(lc[i])
    s=max(s, lc[i][0]-lc[i][2])

print(s)

Submission status: Time Limit Exceeded

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

cnt = 0

if k >= a:
    k = k - a #3
    cnt = cnt + 1*a  #1

    if k >= b:
        k = k - b #1

        if k >= c:
            cnt = cnt + -1*c
            k = k - c

        else:
            for i in range(0, k):
                cnt += -1
                k -= 1
    
    else:
        for i in range(0, k):
            k -= 1

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

Submission status: Time Limit Exceeded

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

s=-1*K*C

lc=[]
lc_=[]
for i in range(A+1):
  for j in range(K-i+1):
    lc.append([i,j,K-i-j])

#print(lc)

for i in range(len(lc)):
  if lc[i][0]<=A and lc[i][1]<=B and lc[i][2]<=C:
    # print(lc[i])
    s=max(s, lc[i][0]-lc[i][2])

print(s)

Submission status: Time Limit Exceeded

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

S = int()

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

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

for i in range(C):
    if K == 0:
        break
    S = S - 1
    K = K - 1

print(S)

Submission status: Time Limit Exceeded

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

#Aの範囲は0<=i<=A
#Bの範囲は0<=j<=B
#Cの範囲は0<=k<=C
#条件より(i+j+k) == K でなければならない
max_k = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i+k+j == K:
                sum_k = i * 1 + j * 0 + k * -1
                if max_k < sum_k:
                    max_k = sum_k
                    
                exit
                
                
print(max_k)

Submission status: Time Limit Exceeded

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

a_card = x[0] # 2
b_card = x[1] # 1
c_card = x[2] # 1
cards = x[3] # 3
y = 0   

while a_card > 0 and cards > 0:
    y += 1
    cards -= 1
    a_card -= 1
while b_card > 0 and cards > 0:
    cards -= 1
    b_card -= 1
while c_card > 0 and cards > 0:
    y -= 1
    cards -= 1
    c_card -= 1

print(y)

Submission status: Time Limit Exceeded

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

s=-1*K*C

lc=[]
lc_=[]
for i in range(K+1):
  for j in range(K-i+1):
    lc.append([i,j,K-i-j])

#print(lc)

for i in range(len(lc)):
  if lc[i][0]<=A and lc[i][1]<=B and lc[i][2]<=C:
    # print(lc[i])
    s=max(s, lc[i][0]-lc[i][2])

print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum = 0
a_3 = int(a[3])
a_0 = a[0]
a_1 = a[1]

for i in range (a_3):
    if a_0 > 0:
        sum += 1
        a_0 -= 1
    elif a_0 == 0 and a_1 > 0:
        sum += 0
        a_1 -= 1
    else: sum -= 1
    
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

L = []
for x in range(0,A):
	L.append(1)
for y in range(0,B):
	L.append(0)
for z in range(0,C):
	L.append(-1)
print(sum(L[0:K]))

Submission status: Time Limit Exceeded

Solution code:
#枚数
a, b, c, k = map(int, input().split())
 
A = a
B = 0
C = -1 * c
 
if k - a >= 0:
    if k -a -b > 0:
        for i in range(c +1):
            if a + b + i == k:
                print(a + (-1)*i)
    else:
        print(a)
else:
    print(k)

Submission status: Time Limit Exceeded

Solution code:
import itertools

A, B, C, K = map(int, input().split(" "))
data = [1 for _ in range(A)] + [0 for _ in range(B)] + [-1 for _ in range(C)]

sums = [sum(conb) for conb in itertools.combinations(data, K)]
print(max(sums))

Submission status: Time Limit Exceeded

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

ans = 0

if(0 <= K-A):
    ans = A
    K = K - A
else :
    ans = K
    K = 0
if(K > 0 & 0 <= K-B):
    K = K - B
elif(K > 0 & 0 > K-B):
    ans = K   
if(K > 0):
    for i in range(0,K):
        ans = ans - 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()]
if C == 0:
    print(A)
else:
    resultList = [ A - c for c in range(C + 1 // 2) if c == K - A - B]
    print(max(resultList))

Submission status: Time Limit Exceeded

Solution code:

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




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

Submission status: Time Limit Exceeded

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

if a == k:
    result = a
else:
    for i in range(k):
        if a != 0:
            result = result + 1
            a = a - 1
        elif a == 0 and b != 0:
            #result変わらず
            b = b - 1
        elif a == 0 and b == 0 and c != 0:
            result = result - 1
            c = c - 1
        else:
            break

print(result)

Submission status: Time Limit Exceeded

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

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
        

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

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

def solve(a,b,c,k):
  s = 0
  while k > 0:
    if a > 0:
      a -= 1
      s += 1
      k -= 1
    elif b > 0:
      b -= 1
      k -= 1
    else:
      c -= 1
      s -= 1
      k -= 1

  return s
    
print(solve(A,B,C,K))

Submission status: Time Limit Exceeded

Solution code:
import sys 
a,b,c,k = map(int,input().split())
max=0
if(a==k):
    print(a)
elif(c==0):
    print(a%k)
    
else:
    while(a>0 and k>0):
        max+=1
        a-=1
        k-=1
    if(k<=0):
        print(max)
    else:
        while(b>0 and k>0):
            b-=1
            k-=1
        if(k<=0):
            print(max)
        else:
            while(c>0 and k>0):
                max-=1
                c-=1
                k-=1
            if(k<=0):
                print(max)

Submission status: Time Limit Exceeded

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

for i in range(k):
    if a != 0:
        result = result + 1
        a = a - 1
    elif a == 0 and b != 0:
        #result変わらず
        b = b - 1
    elif a == 0 and b == 0 and c != 0:
        result = result - 1
        c = c - 1
    else:
        break

print(result)

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 = [ A - c for c in range(C + 1) if c == K - A - B]
print(max(resultList))

Submission status: Time Limit Exceeded

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

d =[]

for i in range(A):
    d.append(1)

for j in range(B):
    d.append(0)

for k in range(C):
    d.append(-1)


d.sort(reverse=True)


KK = 0
for l in range(K):
    N = d[l]
    #print(N)
    KK = KK + N
print(KK)

Submission status: Time Limit Exceeded

Solution code:
def main():
  a, b, c, k = map(int, input().split())
  d = k-a
  
  for i in range(b+1):
    for j in range(c+1):
      hui = [i*0 + j*(-1)]
      
      if i+j == d:
        break
  print(max(hui)+a)
  
main()

Submission status: Time Limit Exceeded

Solution code:

a,b,c,k = map(int,input().split())
ans = (-1)*k

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

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()]
temp = None
for c in range(C + 1):
    if (c == K - A - B):
        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 = (int(x) for x in input().split())
s = 0
for i in range(K):
    if A != 0:
        s += 1
        A -= 1
    elif A == 0 and B != 0:
        s = s
        B -= 1
    elif A == 0 and B == 0:
        s -= 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools

A, B, C, K = map(int, input().split(" "))
data = [1 for _ in range(A)] + [0 for _ in range(B)] + [-1 for _ in range(C)]

conbs = list(itertools.combinations(data, K))
max_val = 0
for conb in conbs:
    if sum(conb) > max_val:
        max_val = sum(conb)
print(max_val)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int,input().split())
ans = 0
for aa in range(a):
    k -=1
    ans+=1
    if k == 0:
        print(ans)
        exit()
for bb in range(b):
        k -=1
        if k == 0:
            print(ans)
            exit()
for bb in range(c):
        k -=1
        ans -= 1
        if k == 0:
            print(ans)
            exit()

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)

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

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 c in range(C + 1):
            if (a + c == K - B):
                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())
count = 0
sum = 0
for a in range(A):
    sum = sum + 1
    count = count + 1
    if count >= K:
        break



for b in range(B):
    if count >= K:
        break
    sum = sum + 0
    count = count + 1




for c in range(C):
    if count >= K:
        break
    sum = sum - 1
    count = count + 1


print(sum)