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:
#!/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=(int(n) for n in input().split())
count = 0
sum = 0
for i in range(a):
    if count == k:
        break
    else:
        count += 1
        sum += 1
for i in range(b):
    if count == k:
        break
    else:
        count += 1
for i in range(c):
    if count == k:
        break
    else:
        count += 1
        sum -= 1
print(sum)

Submission status: Time Limit Exceeded

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

count = 0
ans = 0

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

Submission status: Time Limit Exceeded

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

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

elif A > K:
    print(K)
elif A+B > K:
    print(A)
else:
    for i in reversed(range(0, K)):
        if A > 0:
            count += 1
            A = A - 1
        elif B > 0:
            B = 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:
        ans += 1
        a -= 1

    elif b:
        b -= 1

    elif c:
        ans -= 1
        c -= 1

print(ans)

Submission status: Time Limit Exceeded

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


num_list = []

for a in range(A):
    num_list.append(1)

for b in range(B):
    num_list.append(0)

for c in range(C):
    num_list.append(-1)

ans_list = num_list[0:K]

ans = sum(ans_list)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input().split();
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
k = int(s[3]);
max = 0;
while(k > 0):
    if(a > 0):
        max += 1;
        a -= 1;
        k -= 1;
    elif(b > 0):
        b -= 1;
        k -= 1;
    else:
        max -= 1;
        k -= 1;


print(max);

Submission status: Time Limit Exceeded

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

sum = 0
i = 0

while i < k:
  if i < a:
    sum += 1
    i += 1
  elif i < a + b:
    i += 1
  else:
    sum -= 1
    i += 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
a,b,c,k=list(map(int,input().split()))
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))
print(max(re))

Submission status: Time Limit Exceeded

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

for i in range(N):
    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())

result = 0
for k in range(K):
    if 0 < A:
        result += 1
        A -= 1
    elif 0 < B:
        B -= 1
    else:
        result -= 1
        C -= 1
                
print(result)

Submission status: Time Limit Exceeded

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

count = 0
second = K-A-B

if A >= K:
  count = K
else:
  count = A

if second:
  for j in range(second):
    count -= 1

print(count)

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
        continue
    if b > 0:
        b -= 1
        continue
    if c > 0:
        sum -= 1
        c -= 1
        continue
print(sum)

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

r = 0

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

Submission status: Time Limit Exceeded

Solution code:
s = input().split();
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
k = int(s[3]);
max = 0;
while(k > 0):
    if(a > 0):
        max += 1;
        a -= 1;
        k -= 1;
    elif(b > 0):
        b -= 1;
        k -= 1;
    elif(c > 0):
        max -= 1;
        k -= 1;


print(max);

Submission status: Time Limit Exceeded

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

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

    elif b:
        b -= 1

    elif c:
        ans -= 1
        c -= 1

print(ans)

Submission status: Time Limit Exceeded

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

for j in range(b):
    abc.append(0)

for l in range(c):
    abc.append(-1)

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

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
point = 0
judge = False
if A == K:
  point = A
  judge = True
elif A == 0 and B == K:
  point = 0
  judge = True
elif A == 0 and B == 0 and C == K:
  point = -K
  judge = True
if not judge:
  if A > 0 and K > 0:
    while A > 0 and K > 0:
      K -= 1
      A -= 1
      point += 1
  if B > 0 and K > 0:
    while B > 0 and K > 0:
      K -= 1
      B -= 1
      point += 0
  if C > 0 and K > 0:
    while C > 0 and K > 0:
      K -= 1
      C -= 1
      point -= 1
print(point)

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 A == 0 and B > 0:
        B -= 1
    else:
        ans -= 1
        C -= 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(A):
    lst.append(1)
for j in range(B):
    lst.append(0)
for s in range(C):
    lst.append(-1)

for t in range(K):
    sum += lst[t]

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 i+1 <= A:
        ans += 1
    if A < i+1 <= A + B:
        ans +=0
    if A + B < i+1 <= A + B + C:
        ans = ans - 1
        
print(ans)

Submission status: Time Limit Exceeded

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

while k > 0:
    if a > 0:
        total += 1
        a -= 1
        k -= 1
        continue
    if b > 0:
        b -= 1
        k -= 1
        continue
    if c > 0:
        total -= 1
        k -= 1
        continue
print(total)

Submission status: Time Limit Exceeded

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

for i in range(b):
    l.append(0)

for i in range(c):
    l.append(-1)

for i in range(k):
    sum += l[i]

print(sum)

Submission status: Time Limit Exceeded

Solution code:
#B

A,B,C,K=map(int,input().split())
cnt=0
Sum=0
while True:
    if cnt==K:
        print(Sum)
        break
        
    if A!=0:
        A+=-1
        Sum+=1
        cnt+=1
        continue
        
    elif B!=0:
        B+=-1
        cnt+=1
        continue
        
    elif C!=0:
        C+=-1
        Sum+=-1
        cnt+=1
        continue

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:
A, B, C, K = map(int, input().split())
cards = [1 for _ in range(A)]
cards += [0 for _ in range(B)]
cards += [-1 for _ in range(C)]
print(sum(cards[:K]))

Submission status: Time Limit Exceeded

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

for i in range(B):
    if count >= K:
        print(res)
        exit()
    count += 1

for i in range(C):
    if count >= K:
        print(res)
        exit()
    res -= 1
    count += 1

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
        continue
    elif a == 0 and b > 0:
        b -= 1
        continue
    else:
        count -= 1
        c -= 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
paramA, paramB, paramC, paramK = list(map(lambda x: int(x), input().split(' ')))
params = [1 for i in range(paramA)]
params.extend([0 for i in range(paramB)])
params.extend([-1 for i in range(paramC)])

result = 0
for p in params:
    if paramK > 0:
        result += p
        paramK -= 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 a > 0:
        ans += 1
        a -= 1
        continue   
    if b > 0:
        b -= 1
        continue         
    if c > 0:
        b -= 1
        ans -= 1
        continue     


print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=map(int, input().split())
""" a:1
    b:0
    c:-1
"""
nokori=k
sum_max=0
while nokori>0:
    nokori-=1
    if(a>0):
        sum_max+=1
        a-=1
        continue
    if(b>0):
        b-=1
        continue
    if(c>0):
        sum_max-=1
        c-=1
    

print(sum_max)

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:
        a = a - 1
        suma += 1
    elif b > 0:
        b = b - 1
    elif c > 0:
        c = c - 1
        suma -= 1
print(suma)

Submission status: Time Limit Exceeded

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

card_list = [1 for _ in range(a)] + [0 for _ in range(b)] + [-1 for _ in range(c)] 

print(sum(card_list[:k]))

Submission status: Time Limit Exceeded

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

cnt = 0
ret = 0

while(cnt < k):
  if(a > 0):
    ret += 1
    a -= 1
    cnt += 1
  elif(b > 0):
    b -= 1
    cnt += 1
  else:
    ret -= 1
    c -= 1
    cnt += 1

print(ret)

Submission status: Time Limit Exceeded

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

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

    else:
        if B != 0:
            ans+=0
            B-=1
        else:
            if C != 0:
                ans-=1
                C-=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
ABCK = [int(x) for x in input().split()]
A=ABCK[0]
B=ABCK[1]
C=ABCK[2]
K=ABCK[3]

n=0

while A>0 and K>0:
  n+=1
  K-=1
  A-=1
  
while B>0 and K>0:
  K-=1
  B-=1
  
while C>0 and K>0:
  n-=1
  C-=1
  K-=1
  
print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=map(int,input().split())
aa=0
while(k!=0):
    if(a>0):
        aa+=1
        a-=1
        k-=1
        continue
    if(b>0):
        aa+=0
        b-=1
        k-=1
        continue
    if(c>0):
        aa-=1
        c-=1
        k-=1
        continue
    # k-=1
print(aa)

Submission status: Time Limit Exceeded

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

i = 0
maxSum = 0
while(i<K):
  if(i<A):
    maxSum += 1
  elif(i<A+B):
    maxSum += 0
  elif(i<A+B+C):
    maxSum -= 1
  i+=1
print(maxSum)

Submission status: Time Limit Exceeded

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


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

print(s)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, input().split())
cnt=0
s=0
# print(a,b,c,k)
while a > 0 and cnt < k:
#     print("a")
    s+=1
    a-=1
    cnt+=1
#     print(a,b,c,k, cnt, s)
while b > 0 and cnt < k:
    #print("b")
    s+=0
    b-=1
    cnt+=1
while c > 0 and cnt < k:
    s-=1
    c-=1
    cnt+=1
print(s)

Submission status: Time Limit Exceeded

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

if a > k:
    print(k)
elif a + b > k:
    print(a)
else:
    sum = a
    for i in range(k - a - b):
        sum -= 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:
        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());
num = 0;

while a > 0 and k > 0:
    num += 1;
    a -= 1;
    k -= 1;
  
while b > 0 and k > 0:
    b -= 1;
    k -= 1;
    
while c > 0 and k > 0:
    num -= 1;
    c -= 1;
    k -= 1;

print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(A):
  if now == 0:
    break
  sum += 1 
  now = now - 1

if now != 0:
  for i in range(B):
    if now == 0:
      break
    now = now - 1
    
if now != 0:    
  for i in range(C):
    if now == 0:
      break
    sum -= 1
    now = now - 1
    
print(sum)

Submission status: Time Limit Exceeded

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

if(A == K):
  print(A)
  exit()
if(A+B == K):
  print(A)
  exit()

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

Submission status: Time Limit Exceeded

Solution code:

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def solve(A: int, B: int, C: int, K: int):
    ans=0
    for i in range(K):
        if A>0:
            ans+=1
            A-=1
        elif B>0:
            B-=1
        elif C>0:
            ans-=1
    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

if k < a:
    print(k)
    exit()

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

for i in range(k):
    ans -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin=sys.stdin

ns = lambda:stdin.readline().rstrip()
ni = lambda:int(stdin.readline().rstrip())
nm = lambda:map(int,stdin.readline().split())
nl = lambda:list(map(int,stdin.readline().split()))

A,B,C,K=nm()
ans=0
for i in range(K):
    if(A>0):
        A-=1
        ans+=1
    elif(B>0):
        B-=1
    else:
        C-=1
        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(a):
  if k == 0:
    print(ans)
    exit()
  ans += 1
  k -= 1
for i in range(b):
  if k == 0:
    print(ans)
    exit()
  k -= 1
for i in range(c):
  if k == 0:
    print(ans)
    exit()
  ans -= 1
  k -= 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import os

def file_input():
    f = open('ABC167/input.txt', 'r')
    sys.stdin = f

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
A,B,C,K = LI()
ans = 0
for _ in range(K):
    if A!=0:
        ans +=1
        A -= 1
    elif B!=0:
        B -= 1
    else:
        ans -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#2020-05-10
a,b,c,k = map(int,input().split())
lst = []
for i in range(a):
    lst.append(1)
for i in range(b):
    lst.append(0)
for i in range(c):
    lst.append(-1)
print(sum(lst[:k]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

total = 0
count = 0
for a in range(A):
  total += 1
  count += 1
  if count == K:
    print(total)
    quit()
    
for b in range(B):
  count += 1
  if count == K:
    print(total)
    quit()
    
for c in range(C):
  total -= 1
  count += 1
  if count == K:
    print(total)
    quit()

Submission status: Time Limit Exceeded

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

ans = 0
while(K!=0):
    if A!=0:
        ans += 1
        A -= 1
        K -= 1
    elif B!=0:
        ans += 0
        B -= 1
        K -= 1
    elif 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())
sum=0
while k>0:
    if a>0:
        sum+=1
        a-=1
        k-=1
    elif b>0:
        sum+=0
        b-=1
        k-=1
    else:
        c-=1
        sum-=1
        k-=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k=map(int,input().split())
p=0
for i in range(k):
    if a>0:
        p+=1
        a-=1
    elif b>0:
        p+=0
        b-=1
    elif c>0:
        p-=1
        c-=1
    k-=1
    
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
        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 = map(int, input().split())
cnt = 0
ans = 0
while cnt < k:
    if a > 0:
        a -= 1
        cnt += 1
        ans += 1
    elif b > 0:
        b -= 1
        cnt += 1
    elif c > 0:
        c -= 1
        cnt += 1
        ans -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l = [1 for _ in range(a)] + [0 for _ in range(b)] + [-1 for _ in range(c)]
print(sum(l[:k]))

Submission status: Time Limit Exceeded

Solution code:
A,B,C,K = map(int,input().split())
sum_ = 0
while K > 0:
    if A > 0:
        sum_ += 1
        A -= 1
    elif B > 0:
        B -= 1
    elif C > 0:
        sum_ -= 1
        C -= 1
    K -= 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
    continue
  elif(b!=0):
    b-=1
    continue
  else:
    c-=1
    ans-=1
    continue
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
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a,b,c,k=mii()


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:
def main():
    a,b,c,k = map(int, input().split())
    i = 0
    ans = 0
    while i < k:
        if a:
            a -= 1
            i += 1
            ans += 1
        elif b:
            b -= 1
            i += 1
        else:
            c -= 1
            i += 1
            ans -=1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys

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

r1 = K - A
cnt = A

if B >= r1:
  print(cnt)
  sys.exit()

r2 = r1 - B
print(cnt - r2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k = list(map(int,input().split()))
ans = 0
for x, y in zip([a,b,c], [1,0,-1]):
  if k <= 0:
    break
  ans += min(x,k) * y
  k -= min(x,k)

print(ans)

Submission status: Accepted

Solution code:
#ABC167
A,B,C,K=map(int,input().split())
#----------以上入力----------
if A > K:
    print(K)
elif  A+B >= K:
    print(A)
else:
    print(A-(K-A-B))

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    sum = 0

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

    n = n-b
    if n <= 0:
        print(sum)
        exit()
    
    n = n-c
    if n <= 0:
        sum = sum - (k-(a+b))
        print(sum)
        exit()

main()

Submission status: Accepted

Solution code:
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

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

tmp = 0
res = 0

if k <= a:
    res = k
elif k <= a + b:
    res = a
else:
    res = 2 * a + b - k

print(res)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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