Problem:


Score : 200 points

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

0 \leq A, B, C

1 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with 1s and one card with a 0.
In this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000



Sample input:
2 1 1 3


Sample output:
2

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def printend(t):
    print(t)
    exit()

A,B,C,K = [int(hoge) for hoge in input().split()]
if A>K:
    printend(A)
elif A+B>K:
    printend(A)
else:
    printend(A - (K-A-B))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


print(ans - k)

Submission status: Wrong Answer

Solution code:
a, b, c, k = [int(i) for i in input().split(' ')]
if k <= a:
  print(1 * k)
elif k <= a + b:
  print(1 * a)
else:
  print(1 * a + k * -1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    A,B,C,K=pin()
    ans=A
    K-=(A+B)
    if K<1:print(ans);return
    print(ans-K)
#%%submit!
resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


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

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if a >= k:
  print(a)
  exit()

k -= a
if b >= k:
  print(a)
  exit()

k -= b
print(a-k)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = [int(x) for x in input().split()]
print(A - max(0, K-(A+B)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = A - max(0, (K - (A+B)))
print(ans)

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a,b,c,k = iim()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(max(A, K))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    A, B, C, K = [int(x) for x in input().split()]

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b, c, k = nm()

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def ma():
    return map(int,input().split())
y="Yes"
t="No"
a,b,c,k=ma()
if a+b<=k:
    print(min(a,k))
else:
    print(a-(k-a-b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    a, b, c, k = (int(i) for i in input().split())
    if k <= a+b:
        ans = a
    else:
        ans = a
        k -= a+b
        ans -= k
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, k = map(int, readline().split())
if a + b >= k:
    print(a)
else:
    print(a - (k - a - b))

Submission status: Wrong Answer

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

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

ans = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import *

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): 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 dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

A, B, C ,K = mi()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    A, B, C, K = Scanner.map_int()
    ans = min(K, A)
    K -= ans
    t = min(K, B)
    K -= B
    ans -= min(K, C)
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


a, b, c, k = LI()
if a < k:
    print(a)
else:
    print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = [int(num) for num in input().split(" ")]
sum = 0

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

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D=map(int,input().split())
def ans167(A,B,C,K):
    A_count=0
    B_count=0
    C_count=0
    for i in range(K):
        if A>0:
            A_count+=1
            A-=1
        elif B>0:
            B_count+=1
            B-=1
        else:
            C_count+=1
            C-=1
    return A_count-C_count
print(ans167(A,B,C,D))

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)
l.sort(reverse = True)
for i in range(k) :
    sum += l[i]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int,input().split())
p = []
for m in range(a+1) :
    for n in range(b+1) :
        for l in range(c+1) :
            if k == m+n+l :
                p.append(1*m+0*n+(-1)*l)
print(max(p))

Submission status: Time Limit Exceeded

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

for i in range(a):
    if cun < k:
        cun += 1
        ans += 1
    else:
        break
for i in range(b):
    if cun < k:
        cun += 1
    else:
        break
for i in range(c):
    if cun < k:
        cun += 1
        ans -= 1
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
cards=input()
list=cards.split()
i,j,l=(0,0,0)
min=int(list[2])*(-1)
while i<=int(list[0]):
    while j<=int(list[1]):
        while l<=int(list[2]):
            if i+j+l==int(list[3]):
              new=i*1+j*0+l*(-1)
              if new>min:
                  min=new
            l=l+1
        l=0
        j=j+1
    i=i+1
    l=0
    j=0
print(min)

Submission status: Time Limit Exceeded

Solution code:
cards=input()
list=cards.split()
a=int(list[0])
b=int(list[1])
c=int(list[2])
k=int(list[3])
i,j,l=(0,0,0)
min=c*(-1)
while i<=a:
    while j<=b:
        while l<=c:
            if i+j+l==k:
              new=i*1+j*0+l*(-1)
              if new>min:
                  min=new
            l=l+1
        l=0
        j=j+1
    i=i+1
    l=0
    j=0
print(min)

Submission status: Time Limit Exceeded

Solution code:
cards=input()
list=cards.split()
a=int(list[0])
b=int(list[1])
c=int(list[2])
k=int(list[3])
i=0
j=0
l=0
min=c*(-1)
while i<=a:
    while j<=b:
        while l<=c:
            if i+j+l==k:
              new=i*1+j*0+l*(-1)
              if new>min:
                  min=new
            l=l+1
        l=0
        j=j+1
    i=i+1
    l=0
    j=0
print(min)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

s = []
x = 0

for i in range(a):
    s.append(1)

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

for i in range(c):
    s.append(-1)
    
for i in range(k):
    x += s[i]
    
print(x)

Submission status: Time Limit Exceeded

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

ans = 0
while K:
  K -= 1
  if A:
    ans += 1
    A -= 1
  elif B:
    B -= 1
  else:
    ans -= 1

print(str(ans))

Submission status: Time Limit Exceeded

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

ans = 0
while K:
  if A:
    ans += 1
    A -= 1
  elif B:
    B -= 1
  else:
    ans -= 1
  K -= 1

print(str(ans))

Submission status: Time Limit Exceeded

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

ans = 0
while K:
  if A:
    ans += 1
    A -= 1
  elif B:
    B -= 1
  else:
    ans -= 1

print(str(ans))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(A+1):
  if i > K:
    break
  A_p = i
  
K -= A_p

for i in range(B+1):
  if i > K:
    break
  B_p = i

K -= B_p

for i in range(C+1):
  if i > K:
    break
  C_p = i

K -= C_p
  
print(A_p*1 + C_p*(-1))

Submission status: Time Limit Exceeded

Solution code:
l = input().split()
n1 = int(l[0])
n0 = int(l[1])
n = int(l[2])
k = int(l[3])

ans = 0

for i in range(n1):
    if k < 1:
        break
    k -= 1
    ans += 1

for i in range(n0):
    if k < 1:
        break
    k -= 1
    ans += 0

for i in range(n):
    if k < 1:
        break
    k -= 1
    ans -= 1 

print(ans)

Submission status: Time Limit Exceeded

Solution code:
l = input().split()
n1 = l[0]
n0 = l[1]
n = l[2]
k = l[3]

list = []

for i in range(int(n1)):
    list.append(1)

for i in range(int(n0)):
    list.append(0)

for i in range(int(n)):
    list.append(-1)

ans = 0

for i in range(int(k)):
    ans += int(list[i])

print(ans)

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(A+1):
  for j in range(B+1):
    for l in range(C+1):
      #print (i)
      #print (j)
      #print (l)
      #print("-----")
      if 1*i +0*j+(-1)*l>=sum and i+j+l ==K:
        sum = 1*i +0*j+(-1)*l
print (sum)

Submission status: Time Limit Exceeded

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

total = []
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if i + j + k == K:
        t = i - k
        total.append(t)

print(max(total))

Submission status: Time Limit Exceeded

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

total = []
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if i + j + k == K:
        t = 0
        t = i + 0 - k
        total.append(t)

print(max(total))

Submission status: Time Limit Exceeded

Solution code:
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
    ans = k
    k = 0
else:
    k -= a
    ans = a
while k > 0:
    k -= 1
    if 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())
for i in range(C+1):
    for j in range(B+1):
        for k in range(A+1):
            if i+j+k==K:
                print(-1*i+k)
                exit()

Submission status: Time Limit Exceeded

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

counter = 0
sum = 0
rest = K
while True:
    #print("counter: ", counter, "sum: ", sum, "rest: ", rest)
    if rest == 0:
        break

    if counter < A:
        #print("Add 1")
        sum += 1
    elif counter < A + B:
        #print("Do nothing")
        pass
    else:
        #print("Subtract 1")
        sum -= 1
    counter += 1
    rest -= 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
a = []
b = []
c = []
for x in range(A):
    a.append(1)
for y in range(B):
    b.append(0)
for z in range(C):
    c.append(-1)
sum = 0
arr = a + b + c
for i in range(K):
    sum += arr[i]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, K = map(int, input().split())
card = []

for i in range(a):
    card.append(1)
else:
    for j in range(b):
        card.append(0)
    else:
        for k in range(c):
            card.append(-1)

print(sum(card[0:K]))

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:
        break
    ans += 1
    K -= 1

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

for k in range(C):
    if K == 0:
        break
    ans -= 1
    K -= 1        
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, K = map(int, input().split())
ct = 0
if B == 0:
    if C == 0:
        print(A)
        exit()

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

Submission status: Time Limit Exceeded

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

cards = []
for _ in range(a):
    cards.append(1)
for _ in range(b):
    cards.append(0)
for _ in range(c):
    cards.append(-1)

ans = 0
for i in range(k):
    ans += cards[i]

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a,b,c,k = map(int,input().split())
card = []
for i in range(a):
    card.append(1)
for i in range(b):
    card.append(0)
for i in range(c):
    card.append(-1)
card.sort(key=int,reverse=True)
result = 0
for i in range(k):
    result += card[i]
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


print(Current_Sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

a,b,c,k = list(map(int,input().split()))
a_1 = 1
c_1 = -1

ans = 0

while k > 0:
    if a > 0:
        ans += a_1
        a -= 1
    elif b > 0:
        b -= 1
    else:
        ans += c_1
    k -= 1
print(ans)

Submission status: Time Limit Exceeded

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

if A > K:
  for k in range(K):
    count += 1
elif A + B >= K:
  for a in range(A):
    count += 1
elif A + B < K  and A >= K - A - B:
   for ac in range(A + A + B - K):
    count += 1
else:
  for ca in range(K - A - A - B):
    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(1,k+1) :
    if i <= a :
        ans += 1
    if i >= a+b+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(K):
    if A != 0:
        A -= 1 
        ans += 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())
s = 0
while(0 < a and 0 < k):
    s += 1
    k -= 1
    a -= 1
while(0 < b and 0 < k):
    k -= 1
    b -= 1
while(0 < c and 0 < k):
    s -= 1
    k -= 1
    c -= 1
print(s)

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

Submission status: Time Limit Exceeded

Solution code:
arr = input().split()
a = int(arr[0])
b = int(arr[1])
c = int(arr[2])
k = int(arr[3])
sum = 0
while a > 0 and k > 0:
  sum += 1
  k -= 1
  a -= 1
  
while b > 0 and k > 0:
  k -= 1
  b -= 1
  
while c > 0 and k > 0:
  k -= 1
  sum -= 1
  c -= 1
  
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = []
numA = min([A, K])

for i in range(B + 1):
  if K - numA - i <= C:
    wa = numA - (K - numA - i)
    ans.append(wa)
            
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
# B

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

while(K != 0):
    if(A == 0 and B == 0 and C > 0):
        C -= 1
        max_score += -1
    if(A == 0 and B > 0):
        B -= 1
    if(A > 0):
        A -= 1
        max_score += 1
    K -= 1

print(max_score)

Submission status: Time Limit Exceeded

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

while k > 0:
    if a == 0:
        break
    
    a -= 1
    p += 1
    k -= 1


while k > 0:
    if b == 0:
        break
    
    b -= 1
    k -= 1

while k > 0:
    if c == 0:
        break
    
    c -= 1
    p -= 1
    k -= 1

print(p)

Submission status: Time Limit Exceeded

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

ans = 0
for _ in range(k):
    if a > 0:
        a -= 1
        ans += 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 = list(map(int,input().split()))
A = 1
B = 0
C = -1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    a, b, c, k = map(int, input().split())
    res = 0
    for i in range(a):
        res += 1
    # if k-a > 0:
    #     for i in range(k-a):
    #         res += 0
    if k-a-b > 0:
        for i in range(k-a-b):
            res += -1
    print(res)
                
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#"ありうる値"の最大値なので、K枚選択時はa,b,cの順に選択する

card_num = 0 #カード枚数
card_sum = 0 #値の合計

while card_num < k:
    if a > 0:
        card_sum += 1
        a -= 1
    elif b > 0:
        b -= 1
    elif c > 0:
        card_sum -= 1
        c -= 1
    
    card_num += 1

print(card_sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(K):
    if(A >  i):
        num+=1
    elif(A+B >  i):
        continue
    else:
        num-=1

print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

x = 0
yy = 0

while x != k:
    if a >= 1:
        yy += 1
        a -= 1
        x += 1
       
    elif b >= 1:
        b -= 1
        x += 1
      
    elif c >= 1:
        yy -= 1
        c -= 1
        x += 1
print(yy)

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)
count=0
for i in range(k):
    count += d[i]


print(count)

Submission status: Time Limit Exceeded

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