Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

Solution code:





N, M, K = map(int, input().split())
A = list(map(int, input().split()))
A += [10**18] * M
B = list(map(int, input().split()))
B += [10**18] * N

dp = [[[0, 0, 0] for _ in range(2)] for _ in range(N+M+1)]

# def dfs():

# print(dp)

for i in range(N+M):
    if dp[i][0][0] + A[dp[i][0][1]] > dp[i][1][0] + A[dp[i][1][1]]:
        dp[i+1][0][0] = dp[i][1][0] + A[dp[i][1][1]]
        dp[i+1][0][1] = dp[i][0][1] + 1
        dp[i+1][0][2] = dp[i][0][2]
    else:
        dp[i+1][0][0] = dp[i][0][0] + A[dp[i][0][1]]
        dp[i+1][0][1] = dp[i][0][1] + 1
        dp[i+1][0][2] = dp[i][0][2]

    if dp[i][0][0] + B[dp[i][0][2]] > dp[i][1][0] + B[dp[i][1][2]]:
        dp[i+1][1][0] = dp[i][1][0] + B[dp[i][1][2]]
        dp[i+1][1][1] = dp[i][1][1]
        dp[i+1][1][2] = dp[i][1][2] + 1
    else:
        dp[i+1][1][0] = dp[i][0][0] + B[dp[i][0][2]]
        dp[i+1][1][1] = dp[i][1][1]
        dp[i+1][1][2] = dp[i][1][2] + 1

ans = 0
for i in range(1, N+M+1):
    if dp[i][0][0] > K and dp[i][1][0] > K:
        break
    ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ai = 0
bi = 0
ans = 0

for _ in range(n+m):
    if ai < n and bi < m:
        break
    if ai < n:
        a = A[ai]
    else: 
        a = 10e10
    if bi < m:
        b = B[bi]
    else:
        b = 10e10
    if a > b:
        k -= b
        bi += 1
    else:
        k -= a
        ai += 1
    if k < 0:
        break
    ans += 1


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
time = 0
ans = 0
if (sum(A) + sum(B)) <= k:
    print(len(A)+len(B))
    exit() 
while len(A) != 0 or len(B) != 0:
    if not A:
        time += B[0]
        if time < k:
            ans += 1
            B.popleft()
        else:
            print(ans)
            exit()
    elif not B:
        time += A[0]
        if time < k:
            ans += 1
            A.popleft()
        else:
            print(ans)
            exit()
    else:
        if A[0] <= B[0]:
            time += A[0]
            if time < k:
                ans += 1
                A.popleft()
            else:
                print(ans)
                exit()
        else:
            time += B[0]
            if time < k:
                ans += 1
                B.popleft()
            else:
                print(ans)
                exit()
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
i, j = 0, 0
while True:
    if i<N:
        a = A[i]
    else:
        a = float('inf')
    if j<M:
        b = B[j]
    else:
        b = float('inf')
    if (a==float("inf") and b==float("inf")):
        i += 1
        break
    if ans>=K:
        break
    if a<=b:
        ans += a
        i += 1
    else:
        ans += b
        j += 1
print(i+j-1)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
    a[i] = a[i-1]+a[i]
    if a[i]>1e+9:
        break
for i in range(1,m):
    b[i] = b[i-1]+b[i]
    if b[i]>1e+9:
        break
ans = 0
x = -1
y = m-1
time = k
while True:
    if time<b[0]:
        ans = max(ans,x+1)
        x += 1
        if x==n:
            break
        elif a[x]>k:
            break
        continue
    for i in range(y,-1,-1):
        if time<b[i]:
            y=i-1
            break
    ans = max(ans,x+y+2)
    x += 1
    if x==n:
        break
    elif a[x]>k:
        break
    time = k-a[x]
        
print(ans)

Submission status: Wrong Answer

Solution code:
a = [input() for l in range(0,3)]
a1 = [int(p) for p in a[0].split()]
a2 = [int(p) for p in a[1].split()]
a3 = [int(p) for p in a[2].split()]
a4 = a2 + a3
b = sorted(a4)
c = 0
for i in range(0,len(b)):
    c = c + b[i]
if c == a1[2]:
    print(len(b))
else:
    s = 0
    t = 0
    while s <= a1[2] and t < len(b):
        s = s + b[t]
        t = t + 1
    print(t-1)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
time = 0
ans_a = 0
ans_b = 0
for i in range(N):
    if time + A[i] > K:
        break
    else:
        time += A[i]
        ans_a += 1
for i in range(M):
    if time + B[i] > K:
        break
    else:
        time += B[i]
        ans_b += 1
tmp = ans_a+ans_b

time = 0
ans_a = 0
ans_b = 0
for i in range(M):
    if time + B[i] > K:
        break
    else:
        time += B[i]
        ans_b += 1
for i in range(N):
    if time + A[i] > K:
        break
    else:
        time += A[i]
        ans_a += 1
print(max(tmp,ans_a+ans_b))

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
from collections import deque
a_list = deque(a_list)
b_list = deque(b_list)
count = 0
time = 0
a_count = 0
b_count = 0
a_border = len(a_list)
b_border = len(b_list)
while True:
  if a_count < a_border and b_count < b_border:
    a = a_list.popleft()
    b = b_list.popleft()
    if time + a > k and time + b > k:
      break
    if a<= b:
        count += 1
        time += a
        b_list.appendleft(b)
        a_count += 1
    else:
        count += 1
        time += b
        a_list.appendleft(a)
        b_count += 1
  elif a_count == a_border and b_count == b_border:
    break
  elif a_count == a_border:
    b = b_list.popleft()
    if time + b > k:
      break
    else:
      count += 1
      time += b
      b_count += 1
  elif b_count == b_border:
    a = a_list.popleft()
    if time + a > k:
      break
    else:
      count += 1
      time += a
      a_count += 1
 

    
    
  
print(count)

Submission status: Wrong Answer

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

import sys

def main():
    n,m,k = map(int,input().split())
    a_desk_list=[]
    b_desk_list=[]
    a_desk_list = list(map(int,input().split()))
    b_desk_list = list(map(int,input().split()))
    counter=0
    read_book_time=0
    if k < a_desk_list[0] and k < b_desk_list[0]:
        print(0)
        exit
    else:
        while k > read_book_time:
            if len(a_desk_list) >0 and len(b_desk_list) > 0:
                if a_desk_list[0] < b_desk_list[0]:
                    read_book_time=a_desk_list.pop(0)
                    k=k-read_book_time
                    counter+=1
                else:
                    read_book_time=b_desk_list.pop(0)
                    k=k-read_book_time
                    counter+=1
            elif len(a_desk_list)==0:
                read_book_time=b_desk_list.pop(0)
                k=k-read_book_time
                counter+=1
            elif len(b_desk_list)==0:
                read_book_time=a_desk_list.pop(0)
                k=k-read_book_time
                counter+=1
            else:
                break
        print(counter)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time = 0
count = 0
i = 0
j = 0
A = a[0]
B = b[0]
while i <len(a) or j <len(b):
    if A<=B:
        time += A
        i += 1
        if i < len(a):
            A = a[i]
        else:
            A = 10 ** 10
    else:
        time += B
        j += 1
        if j < len(b):
            B = b[j]
        else:
            B = 10 ** 10
    if time > k:
        break
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
A.append(1000000000)
B = list(map(int, input().split()))
B.append(1000000000)
time = 0
numA = 0
numB = 0

while time < K:
    if A[numA] < B[numB]:
        time += A[numA]
        if time <= K:
            numA += 1
        else:
            break
    else:
        time += B[numB]
        if time <= K:
            numB += 1
        else:
            break

print(numA + numB)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[0]*n
b=[0]*m
a=list(map(int,input().split()))
b=list(map(int,input().split()))

now=0
ans=0
flag=0
a_now=-1
b_now=m-1
num_a=0
num_b=sum(b)

while b_now>=0 and a_now<n:
    if (num_a+num_b<=k):
        ans=max(ans,a_now+b_now+2)
        a_now+=1
        if (a_now==n):
          break
        num_a+=a[a_now]
    else:
        b_now-=1
        if (b_now==-1):
          break
        num_b-=b[b_now+1]
    
print(ans)

Submission status: Wrong Answer

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

ans = 0
num_n = 0
num_m = 0
time = 0
while ans < n+m:
  if num_n == n and num_m == m:
    break
  if num_n == n:
    tmp = b[num_m]
    num_m += 1
  elif num_m == m:
    tmp = a[num_n]
    num_n += 1
  else:
    if a[num_n] >= b[num_m]:
      tmp = b[num_m]
      num_m += 1
    else:
      tmp = a[num_n]
      num_n += 1
      
  if time + tmp <= k:
    time += tmp
    ans += 1
  else:
    break

print(ans)

Submission status: Wrong Answer

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

A.extend(B)

A = sorted(A)

ans = 0
for i in range(len(A)):
    K = K -A[i]
    if K < 0:
        break
    ans = ans+1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
flag = 0

if A[0] < B[0]:
    switch = 0
else:
    switch = 1

kiroku = 0
num = 0

while flag != 1:
    if switch == 0 or switch == 10:
        kiroku += A.popleft()
        
        if kiroku > K:
            break
            
        num += 1
        
        if len(A) == 0:
            switch = 11
            if len(B) == 0:
                break
                
    elif switch == 1 or switch == 11:
        kiroku += B.popleft()
        
        if kiroku > K:
            break
        
        num += 1
        
        if len(B) == 0:
            switch = 10
            if len(A) == 0:
                break
                
    if switch < 9:
        if A[0] < B[0]:
            switch = 0
        else:
            switch = 1
            
print(num)

Submission status: Wrong Answer

Solution code:
import bisect
n,m,k = map(int,input().split())
*a, = map(int,input().split())
*b, = map(int,input().split())

sa = [0] * n
sa[0] = a[0]
for i in range(1,n):
    sa[i] = sa[i-1] + a[i]
sb = [0] * m
sb[0] = b[0]
for i in range(1,m):
    sb[i] = sb[i-1] + b[i]

ans = 0
for i in range(n):
    if sa[i] > k:break
    rest = k - sa[i]
    a_s = i + 1
    b_s = bisect.bisect(sb,rest) 
    ans = max(ans, a_s + b_s)
print(ans)

Submission status: Wrong Answer

Solution code:
n_m_k = input().split()
n = int(n_m_k[0])
m = int(n_m_k[1])
k = int(n_m_k[2])

a_str_list = input().split()
a_int_list = [int(x) for x in a_str_list]

b_str_list = input().split()
b_int_list = [int(x) for x in b_str_list]

sum_t = 0
cnt_a = 0
cnt_b = 0

len_a = len(a_int_list)
len_b = len(b_int_list)
while(1):
    if((cnt_a != len_a) and (cnt_b != len_b)):
        if(a_int_list[cnt_a] < b_int_list[cnt_b]):
            sum_t += a_int_list[cnt_a]
            if(sum_t <= k):
                cnt_a += 1
            else:
                break
        else:
            sum_t += b_int_list[cnt_b]
            if(sum_t <= k):
                cnt_b += 1
            else:
                break
    elif(cnt_a < len_a):
        sum_t += a_int_list[cnt_a]
        if(sum_t <= k):
            cnt_a += 1
        else:
            break
    elif(cnt_b < len_b):
        sum_t += b_int_list[cnt_b]
        if(sum_t <= k):
            cnt_b += 1
        else:
            break
    else:
        break

print(cnt_a + cnt_b)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
pa = abs(N-M) + 1
A = list(map(int, input().split()))+ [1000000010]
B = list(map(int, input().split()))+ [1000000010]
if N < M:
    A = A + [1000000010]*(pa)
elif N > M:
    B = B + [1000000010]*(pa)
c = 0
while K >= A[0] or K >= B[0]:
    if A[0] < B[0]:
        K -= A.pop(0)
    else:
        K -= B.pop(0)
    c += 1
print(c)

Submission status: Wrong Answer

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

total = 0
cnt = 0

while total <= K:
    if A == [] and  B == []:
        cnt += 1
        break
    elif A == []:
        total += B.pop(0)
    elif B == []:
        total += A.pop(0)
    elif A[0] > B[0]:
        total += A.pop(0)
    else:
        total += B.pop(0)
    cnt += 1

print(cnt-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

def doku(li, K, time):
  cnt = 0
  for i in range(len(li)):
    if time+li[0] <= K:
      time += li[0]
      li.popleft()
      cnt += 1
    else:
      return cnt
  return cnt

ans = 0
time = 0
while time+min(A[0], B[0]) <= K:
  plus = min(A[0], B[0])
  time += plus
  ans += 1
  if A[0] <= B[0]:
    A.popleft()
    if not A:
      ans += doku(B, K, time)
      break;
  else:
    B.popleft()
    if not B:
      ans += doku(A, K, time)
      break;
    
print(ans)

Submission status: Wrong Answer

Solution code:
temp = [int(i) for i in input().split(" ")]
n = temp[0]
m = temp[1]
k = temp[2]

a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]


a.extend(b)

a.sort()


time = 0
counter = 0
for i in range(len(a)):
    
    temp = a[i]

    time += temp
    if time <= k:
        counter += 1
    else:
        break

print(counter)

Submission status: Wrong Answer

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

# 全部Aから選んでみる
minutes_a = 0
count_a = 0
for i in range(N):
    if minutes_a + A[i] > K:
        break
    minutes_a += A[i]
    count_a += 1

minutes_b = 0
count_b = 0

if minutes_a < K:
    for i in range(M):
        if minutes_a + minutes_b + B[i] > K:
            break
        minutes_b += B[i]
        count_b += 1


max_count = count_a + count_b

for i in range(count_b, M):
    if minutes_a + minutes_b + B[i] > K:
        if count_a > 0 and minutes_a - A[count_a - 1] + minutes_b + B[i] <= K:
            minutes_a -= A[count_a - 1]
            count_a -= 1
            minutes_b += B[i]
            count_b += 1
            continue
        else:
            break
    minutes_b += B[i]
    count_b += 1

print(count_a + count_b)

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))
t = 0
x, y = a.popleft(), b.popleft()

if sum(a) + sum(b) <= k:
    print(n + m)
    exit()

while True:
    if x > y:
        k -= y
        if b:
            y = b.popleft()
        else:
            y = float("inf")
    else:
        k -= x
        if a:
            x = a.popleft()
        else:
            x = float("inf")

    if k <= 0:
        break
    t += 1
print(t)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
t=0
for p in range(n):
    if t+a[p]>k:
        p-=1
        break
    t+=a[p]
for q in range(m):
    if t+b[q]>k:
        q-=1
        break
    t+=b[q]
ans=p+q+2
if q<m-1:
    z=ans
    r=0
    for s in range(p,-1,-1):
        t-=a[s]
        z-=1
        while r<m and t+b[r]<=k:
            t+=b[r]
            r+=1
            z+=1
        if z>ans:
            ans=z
        if r==m:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
sum,count = 0,0
for _ in range(N+M+1):
    if sum>K:
        break
    else:
        if A and B:
            if A[0]<B[0]:
                sum+=A.pop(0)
                count+=1
            else:
                sum+=B.pop(0)
                count+=1
        elif not A and B:
            sum+=B.pop(0)
            count+=1
        elif not B and A:
            sum+=A.pop(0)
            count+=1
        else:
            print(count)
            exit()
print(count-1)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))

ans = 0
time = 0

while True:
    if len(a) == 0 and len(b) == 0:
        break

    if len(a) < 1:
        b_pop = b.popleft()
        time += b_pop
        if time > k:
          break
        ans += 1
        continue

    if len(b) < 1:
        a_pop = a.popleft()
        time += a_pop
        if time > k:
          break
        ans += 1
        continue

    if a[0] < b[0]:
        a_pop = a.popleft()
        time += a_pop
    else:
        b_pop = b.popleft()
        time += b_pop

    if time > k:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:

n,m,k = map(float,input().split())

a = list(map(float,input().split()))[::-1]
b = list(map(float,input().split()))[::-1]

#print(a)
#print(b)
ans = 0
while 1:
    print(k, a,b)
    if b == [] and a == []:
        break
    elif b == [] and a != []:
        if a[-1] <= k:
            k -= a.pop()
            ans += 1
            continue
        else:
            break
    elif a == [] and b != []:
        if b[-1] <= k:
            k -= b.pop()
            ans += 1
            continue
        else:
            break
    if a[-1] > b[-1]:
        if b[-1] <= k:
            k -= b.pop()
            ans += 1
        else:
            break
    else:
        if a[-1] <= k:
            k -= a.pop()
            ans += 1
        else:
            break



print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
total = 0
a = 0
b = 0

while total <= K:
    if a + b == N + M:
        print(a + b)
        sys.exit()
    if a == len(A):
        total = total + B[b]
        b = b + 1
        continue
    if b == len(B):
        total = total + A[a]
        a = a + 1
        continue

    if A[a] <= B[b]:
        total = total + A[a]
        a = a + 1
    else:
        total = total + B[b]
        b = b + 1

answer = a + b - 1
print(answer)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#N=int(input())
import numpy
N,M,K=map(int, input().split())
AList=list(map(int, input().split()))
BList=list(map(int, input().split()))
#AList.extend(BList)
#AList=sorted(AList)
#print(AList)
#AList=list(numpy.cumsum(AList))
#BList=list(numpy.cumsum(BList))
#print(AList)
SUM=0
cnt=0
AI=0
BI=0
for i in range(N+M):
    if AI>=N:
        if BI<M and SUM+BList[BI]<=K:
            SUM+=BList[BI]
            BI+=1
            cnt+=1
        else:
            break
    elif BI>=M:
        if AI<N and SUM+AList[AI]<=K:
            SUM+=AList[AI]
            AI+=1
            cnt+=1
        else:
            break
    else:
        if AI<N and AList[AI]<=BList[BI] and SUM+AList[AI]<=K:
            SUM+=AList[AI]
            AI+=1
            cnt+=1
        elif BI<M and AList[AI]>=BList[BI] and SUM+BList[BI]<=K:
            SUM+=BList[BI]
            BI+=1
            cnt+=1
        else:
            break
        
print(cnt)

Submission status: Wrong Answer

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

total = 0
i = 0
for i in range(0, len(c)):
    # print(total)
    # print(c[i])
    total += c[i]

    if total > k:
        i = i-1
        break

print(i+1)

Submission status: Wrong Answer

Solution code:
M, N, K = map(int, input().split())
A = map(int,input().split())
B = map(int,input().split())
C, H, N = list(A) + list(B), 0, 0
if min(C) < K:
  while H < K:
    min_hour = min(C)
    H += min_hour
    if H <= K:
      N += 1
    C.remove(min_hour)
print(N)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
A, B, t = list(map(int, input().split()))
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
c = 0
s = 0
for i in range(len(a)):
    c = np.sum(a[:i])
    if c > t:
        if i > s:
            s = i-1
        break
    for j in range(len(b)):
        c = np.sum(a[:i])+np.sum(b[:j])
        if c > t:
            if i+j-1 > s:
                s = i+j-1
            break
if np.sum(a)+np.sum(b) <= t:
    s = A+B
print(s)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

sum = 0
count = 0


while sum < k:
    if not a_list and not b_list:
        break
    elif not a_list:
        sum += b_list[0]
        b_list.pop(0)
        count += 1
    elif not b_list:
        sum += a_list[0]
        a_list.pop(0)
        count += 1
    elif a_list[0] <= b_list[0]:
        sum += a_list[0]
        a_list.pop(0)
        count += 1
    elif a_list[0] >= b_list[0]:
        sum += b_list[0]
        b_list.pop(0)
        count += 1
    if sum > k:
        count -= 1
    
print(count)

Submission status: Wrong Answer

Solution code:
#ABC172 C
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

time = 0
count = 0
while time < k:
  if a[0] < b[0]:
    time += a[0]
    a.pop(0)
  else:
    time += b[0]
    b.pop(0)
  count += 1
  if a == [] or b == []:
    break
#print(a)
#print(b)
c = a+b
#print(c)
#print(count)
while time < k:
  time += c[0]
  c.pop(0)
  count += 1

if time == k:
  print(count)
else:
  print(count-1)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
A = A + [10*10]
B = list(map(int, input().split()))
B = B + [10*10]
for i in range(M):
    A.insert(2*i, B[i])


time = 0
count = -1
while  time <= K :
    x = min(A[:2])
    A.remove(x)
    time += x
    count += 1

print(count)

Submission status: Wrong Answer

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

time = 0
cnt = 0


def isa(n):
    if len(a) == 0:
        return False
    elif len(b) == 0:
        return True
    elif a[n] < b[n]:
        return True
    elif a[n] > b[n]:
        return False
    elif n-1 > len(a)-1 or n-1 > len(b)-1:
        isa(n + 1)
    else:
        if len(a) == 0:
            return False
        else:
            return True


for i in range(len(a) + len(b)):
    if isa(0):
        if time + a[0] > k:
            break
        time += a.pop(0)

    else:
        if time + b[0] > k:
            break
        time += b.pop(0)
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A=[0]+A
B=[0]+B

from itertools import accumulate

AA=list(accumulate(A))
BB=list(accumulate(B))



print(AA)
print(BB)

timer=0
count=0
a,b=0,0

import bisect
for i in range(N+1):
    a=i
    b=bisect.bisect_right(BB,K-AA[i])-1
    if b==-1:
        continue
    count=max(count,a+b)
    #print(a,b,count,AA[a]+BB[b])
print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


def main():
    N, M, K = inpl()
    A = inpl()
    B = inpl()
    A.append(float("inf"))
    B.append(float("inf"))
    a, b = 0, 0
    while True:
        if A[a] > K and B[b] > K:
            break
        elif A[a] <= B[b]:
            K -= A[a]
            a += 1
        elif B[b] < A[a]:
            K -= B[b]
            b += 1

    print(a + b)

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
x=input()
x0=x.split()
n=int(x0[0])
m=int(x0[1])
k=int(x0[2])
a=input()
b=input()
a0=[int(i) for i in a.split()]
b0=[int(i) for i in b.split()]
a=0
b=0
al=list([0])
bl=list([0])
for i in range(n):
    a=a+a0[i]
    if a>k:
        break
    al.append(a)
for i in range(m):
    b=b+b0[i]
    if b>k:
        break
    bl.append(b)
for i in range(len(al)):
    for l in range(len(bl)):
        if al[-i-1]+bl[-l-1]<=k:
            print(len(al)+len(bl)-i-l-2)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
input = sys.stdin.readline

N,M,K=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A_acc = list(accumulate(A))
B_acc = list(accumulate(B))
a = 0
b = 0
ans = 0
deep = ""
for n,z in enumerate(zip(A_acc,B_acc)):
    i,j = z
    if i < j and i <= K:
        deep = 'A'
    elif j <= K:
        deep = 'B'
    else:
        break
    ans += 1
if deep == 'A':
    K -= A_acc[n]
    s = B
else:
    K -= B_acc[n]
    s = A
for i in s:
    if K >= i:
        ans += 1
        K -= i
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

a, b = 0, 0

while k > 0:
  if a < n and b < m:
    if As[a] < Bs[b]:
      if k < As[a]:break
      k -= As[a]
      a += 1
    else:
      if k < Bs[b]:break
      k -= Bs[b]
      b += 1
  elif a < n:
    if k < As[a]:break
    k -= As[a]
    a += 1
  elif b < m:
    if k < Bs[b]:break
    k -= Bs[b]
    b += 1
  else:
    break

print(a+b)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
S=sum(A)+sum(B)
count=len(A)+len(B)

for i in range(len(A)+len(B)):
  if S > K:
    if A[-1] >= B[-1]:
      S -= A[-1]
      count -= 1
    else:
      S -= B[-1]
      count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
x = input().split()
y = input().split()
z = input().split()
s = 0

for nn in range(2000000):
    if int(x[2]) < 0:
        break
    if int(y[0]) <= int(z[0]) :
        x[2] = int(x[2]) - int(y[0])
        del y[0]  
        y.append(1000000001) 
        s += 1
    else:
        x[2] = int(x[2]) - int(z[0])
        del z[0]
        z.append(1000000001)
        s += 1
print(s-1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

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

csumA = []
csumB = []

s = 0
for i in A:
    s += i
    csumA.append(s)
s = 0
for i in B:
    s += i
    csumB.append(s)

ans = 0
for i in range(N):
    if K - csumA[i] > 0:
        ans = max(ans,i+1+bisect(csumB,max(0,K-csumA[i])))

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
 
a_i, b_i = 0, 0
remain = K
count_of_book = 0
 
while True:
  if a_i < N and A[a_i] <= remain:
    remain -= A[a_i]
    a_i += 1
    enough_A = True
    count_of_book += 1
  else:
    enough_A = False
    
  if b_i < M and B[b_i] <= remain:
    remain -= B[b_i]
    b_i += 1
    enough_B = True
    count_of_book += 1
  else:
    enough_B = False
    
  if not (enough_A and enough_B):
    break
print(count_of_book)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N,M,K = map(int,input().split())
A = list(map(int,stdin.readline().split()))
B = list(map(int,stdin.readline().split()))

index_A = 0
index_B = 0
now = 0
count = 0

while True:
    if A[index_A] >= B[index_B]:
        if now + B[index_B] <= K:
            now += B[index_B]
            index_B += 1
            count += 1
        else:
            break
    else:
        if now + A[index_A] <= K:
            now += A[index_A]
            index_A += 1
            count += 1
        else:
            break
    if index_A > len(A)-1 or index_B > len(B)-1:
        break

if index_A > len(A)-1:
    while True:
        if now+B[index_B] <= K:
            now += B[index_B]
            count += 1
            index_B += 1
            if index_B > len(B)-1:
                break
        else:
            break
else:
    while True:
        if now + A[index_A] <= K:
            now += A[index_A]
            count += 1
            index_A += 1
            if index_A > len(A)-1:
                break
        else:
            break
print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
nowK = K
for A_idx in range(len(A)):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
if A_idx == 0:
    print(ans)
    exit()
tmp_ans = ans
for i in range(A_idx, -1, -1):
    nowK -= A[i]
    tmp_ans -= 1
    for j in range(B_idx, M):
        if nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
    B_idx = j
    ans = max(tmp_ans, ans)
print(ans)