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 = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

i, j = 0, 0
readed = 0
count = 0

while True:
    if i >= n:
        if j >= m:
            break
        else:
            readed += b[j]
            j += 1
    elif j >= m:
        readed += a[i]
        i += 1
    elif a[i] < b[j]:
        readed += a[i]
        i += 1
    elif a[i] == b[j]:
        if i+1 < n and j+1 < m:
            if a[i+1] <= b[j+1]:
                readed += a[i]
                i += 1
            else:
                readed += b[j]
                j += 1
        elif i+1 < n:
            readed += a[i]
            i += 1
        elif i+1 < m:
            readed += b[j]
            j += 1
        else:
            readed += b[j]
            j += 1  

    else:
        readed += b[j]
        j += 1
    if readed > 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()))[::-1]
B = list(map(int, input().split()))[::-1]

t = 0
count = 0
while t <= K:
    if A and not B:
        if t + A[-1] <= K:
            t += A.pop()
            count += 1
        else:
            break
    elif not A and B:
        if t + B[-1] <= K:
            t += B.pop()
            count += 1
        else:
            break
    elif A and B:
        if A[-1] < B[-1] and t + A[-1] <= K:
            t += A.pop()
            count += 1
        elif t + B[-1] <= K:
            t += B.pop()
            count += 1
        else:
            break
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    N, M, K = map(int, input().split())
    A = deque(map(int, input().split()))
    B = deque(map(int, input().split()))
    time = 0
    idxA = N
    idxB = M

    time = 0
    for i in range(N):
        time += A[i]
        if time > K:
            idxA = i
            break
    if idxA < N: time -= A[idxA]
    for j in range(M):
        time += B[j]
        if time > K:
            idxB = j
            break

    if idxA == N and idxB == M:
        print(N + M)
        return

    ans = idxA + idxB
    for i in range(idxA - 1, -1, -1):
        time -= A[i]
        while time <= K and idxB < M:
            time += B[idxB]
            idxB += 1
        time -= B[idxB - 1]
        idxB -= 1
        #print(i, idxB)
        ans = max(ans, i + idxB)
    print(ans)


if __name__ == "__main__":
    main()

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

ans = 0
ai = 0
bi = 0
t = 0
for i in range(n+m):
  if t > k:
    break
  if ai == n-1 and bi == m-1:
    break
  if ai >= n:
    t += b_list[bi]
    bi += 1
    ans += 1
  elif bi >= m:
    t += a_list[ai]
    ai += 1
    ans += 1
  elif a_list[ai] > b_list[bi]:
    t += b_list[bi]
    bi += 1
    ans += 1
  else:
    t += a_list[ai]
    ai += 1
    ans += 1
if t <= k:
  print(ans)
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import bisect

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n,m,k = Ri()

a = Ri()
b = Ri()

arr1 = [0]*n
arr2 = [0]*m

arr1[0] = a[0]
arr2[0] = b[0]

for i in range(1,n):
    arr1[i] = arr1[i-1]+a[i]

for i in range(1,m):
    arr2[i] = arr2[i-1]+b[i]

ans = 0
for i in range(n+1):
    if i == 0:
        ind = bisect.bisect_right(arr2, k)
        ind-=1
        ans=  max(ans, i+ind+1)
        # print(ans)
    else:
        if k -arr1[i-1] >= 1:
            ind = bisect.bisect_right(arr2, k-arr1[i-1])
            ind-=1
            ans=  max(ans, i+ind+1)
    # print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
s=0
maxa=-5
N,M,K=map(int,input().split())
L=list(map(int,input().split()))
R=list(map(int,input().split()))
for i in range(N):
  s+=L[i]
  if s>=K:
    t=i
    break
  if i==N-1:
    t=i+1
for i in range(t+1):
  if i==t:
    n=K
  else:
    n=K-sum(L[:i+1])
  for j in range(M):
    n=n-R[j]
    if n<0:
      if i==t:
        maxa=max(maxa,j)
      else:
        maxa=max(maxa,j+i+1)
      break
    if j==M-1:
      if i==t:
        maxa=max(maxa,j+1)
      else:
        maxa=max(maxa,j+i+2)
print(maxa)

Submission status: Wrong Answer

Solution code:

from collections import deque



# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
from bisect import bisect_left as bl
def main():

    # n = int(input())
    # l = [int(j) for j in input().split()]
    
# 3 4 240
# 60 90 120
# 80 150 80 150

    # for t in range(int(input())):

    n,m,k = [int(j) for j in input().split()]
    l1 = [0]+[int(j) for j in input().split()]
    l2 = [0]+[int(j) for j in input().split()]

    # pre = [0]*n
    i = 0
    j = 0
    for i in range(1,n+1):
        l1[i] += l1[i-1]
    for i in range(1,m+1):
        l2[i] += l2[i-1]

    # print(l1, l2)
    ans =0 
    for i in range(n+1):
        if l1[i]>k: 
            break
        x = bl(l2, k-l1[i])
        if x<m and x>0:
            if l2[x]>k-l1[i]:
                x = x-1
        ans = max(ans, x+i)
    print(ans)






# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
Af = False
Bf = False
count = 0

for _ in range(n+m):
  if Af and Bf:
    break
  if A[0] > k and B[0] > k:
    break
  if Af:
    k -= B.pop(0)
    count += 1
    if len(B)==0:
      B.append((10**9)+1)
      Bf = True
    continue
  if Bf:
    k -= A.pop(0)
    count += 1
    if len(A)==0:
      A.append((10**9)+1)
      Af = True
    continue
  if A[0] < B[0]:
    k -= A.pop(0)
    count += 1
    if len(A)==0:
      A.append((10**9)+1)
      Af = True
  else:
    k -= B.pop(0)
    count += 1
    if len(B)==0:
      B.append((10**9)+1)
      Bf = True
print(count)

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:
a,b,c = map(int,input().split())
d = input().split()
d = [int(i) for i in d]
e = input().split()
e = [int(i) for i in e]
d.sort()
e.sort()
if len(d) != len(e):
    if len(d) >= len(e):
        for i in range(len(d) - len(e)):
            e.append(0)
    else:
        for i in range(len(e) - len(d)):
            d.append(0)
x = 0
y = 0
for i in range(len(d) + len(e)):
    if x >= c:
        break
    else:
        if x + d[i] >= c:
            break
        else:
            x = x + d[i]
            y = y + 1
            if x + e[i] >= c:
                break
            else:
                x = x + e[i]
                y = y + 1
print(y)

Submission status: Wrong Answer

Solution code:
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

N, M, K = nn()
A = nn()
B = nn()

a = []
sum_a = 0
for i in A:
    sum_a += i
    a.append(sum_a)

b = []
sum_b = 0
for i in B:
    sum_b += i
    b.append(sum_b)

#print(a, b)
ans = -1
for i in range(len(a)):
    ai = a[i]
    if ai > K:
        break

    tmp = K - ai

    j = bisect_right(b, tmp) - 1
    if j == -1:
        continue

    bi = b[j]
    #print(i, j, a, b, ai, bi, ai + bi)   
    if i + j > ans:
        ans = i + j

if ans >= 0:
    print(ans+2)
else:
    print(0)

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

count = 0
book = 0
while True:
  if len(A) == len(B) == 0:
    break
  elif len(A) == 0:
    count += B[0]
    B.pop(0)
  elif len(B) == 0:
    count += A[0]
    A.pop(0)
  else:
    if A[0] < B[0]:
      count += A[0]
      A.pop(0)
    elif A[0] > B[0]:
      count += B[0]
      B.pop(0)
    elif A[0] == B[0]:
      if len(A) == 1:
        count += B[0]
        B.pop(0)
      elif len(B) == 1:
        count += A[0]
        A.pop(0)
      else:
        if A[1] >= B[1]:
          count += B[0]
          B.pop(0)
        else:
          count += A[0]
          A.pop(0)
  if count > K:
    break
  book += 1

print(book)

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    cost = 0
    count = 0
    while True:
        if len(A) ==0 and len(B) == 0:
            break
        elif len(A) == 0:
            b = B[0]
            if b + cost > K:
                break
            cost += b
            B = B[1:]
        elif len(B) == 0:
            if a + cost > K:
                break
            cost += a
            A = A[1:]

        else:
            a = A[0] 
            b = B[0] 
            if a < b:
                if a + cost > K:
                    break
                cost += a
                A = A[1:]
            else:
                if b + cost > K:
                    break
                cost += b
                B = B[1:]

        count += 1
    
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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]

for i in range(1, M):
    B[i] += B[i - 1]

ans = 0

for i, a in enumerate(A):
    time = K - a
    if time < 0:
        continue
    cnt = i + 1
    cnt += bisect(B, time)
    ans = max(ans, cnt)

print(ans)

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

a=0
b=0
count=0

while K >= 0:
    if A_list[int(a)] <= B_list[int(b)]:#Aの机にある本のほうが短い時間で読めるとき
        K-=A_list[int(a)]
        a+=1
    else:#Bの机にある本のほうが短い時間で読めるとき
        K-=B_list[int(b)]
        b+=1
    count+=1
    if a >= len(A_list):#リストが空だったら
        A_list.append(10**9+1)
    if b >= len(B_list):#リストが空だったら
        B_list.append(10**9+1)

print(count-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    now_A = 0
    now_B = 0
    ans = 0
    minute = 0

    MAX = 10 ** 9 + 1

    for _ in range(N + M):
        AA = A[now_A] if now_A < N else MAX
        BB = B[now_B] if now_B < M else MAX

        if (AA < BB):
            now_A += 1
            minute += AA
        elif (AA >= BB):
            now_B += 1
            minute += BB

        if (minute > K or (AA == BB and BB == MAX)):
            break

        ans += 1

    print(ans)

resolve()

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()))
# if n > m:
#     b += [10**9+1]*(n-m)
# elif m > n:
#     a += [10**9+1]*(m-n)

t = 0
i, j = 0, 0
ans = 0
while i < n or j < m:
    if i >= n:
        if t + b[j] <= k:
            t += b[j]
            j += 1
        else:
            break
    elif j >= m:
        if t + a[i] <= k:
            t += a[i]
            i += 1
        else:
            break
    else:
        if a[i] <= b[j]:
            if t + a[i] <= k:
                t += a[i]
                i += 1
            else:
                break
        else:
            if t + b[j] <= k:
                t += b[j]
                j += 1
            else:
                break
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_in = list(map(int, input().split()) )
B_in = list(map(int, input().split()) )
from collections import deque

A = deque(A_in)
B = deque(B_in)

T = 0
N_book = 0
for i in range(len(A) + len(B)):
    if len(A)==0:
        if T+B[0] > K:
            break
        else:
            N_book+=1
            T+=B.popleft()
    elif len(B)==0:
        if T+A[0] > K:
            break
        else:
            N_book+=1
            T+=A.popleft()
    else:
        a = A[0]
        b = B[0]
        if T+min(a, b) > K:
            break
        elif a >= b:
            N_book+=1
            T+=B.popleft()
        else:
            N_book+=1
            T+=A.popleft()
print(N_book)

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.append(10**10)
B.append(10**10)

A_ruiseki = [A[0]]
for i in range(1, n):
    if A_ruiseki[i-1]+A[i] <= k :
        A_ruiseki.append(A_ruiseki[i-1]+A[i])
    else:
        break
print(A_ruiseki)
ans = 0

for i in range(len(A_ruiseki)):
    time = A_ruiseki[i]
    if time > k:
        continue
    cnt_b = 0
    while cnt_b < m:
        if time + B[cnt_b] <= k:
            time += B[cnt_b]
            cnt_b += 1
        else:
            break

    ans = max(ans, (i+1) + cnt_b)

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()))
import itertools
A = list(itertools.accumulate(A))+[10**18]
B = list(itertools.accumulate(B))+[10**18]
ans=0
ai,bi=0,0
a=(ai+1)/A[ai]
b=(bi+1)/B[bi]
ak,bk=0,0
while ak+bk<K:
  if a>=b:
    ans+=1
    ak=A[ai]
    if ak+bk>K:
      ans-=1
      break
    if ai+1<N+1:
      ai+=1
      a=(ai+1)/A[ai]
    else:
      break
  else:
    ans+=1
    bk=B[bi]
    if ak+bk>K:
      ans-=1
      break
    if bi+1<M+1:
      bi+=1
      b=(bi+1)/B[bi]
    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()))
ans=0
ati=[a[0]]
bti=[b[0]]
for i in range(1,n):
  ati.append(ati[i-1]+a[i])
for i in range(1,m):
  bti.append(bti[i-1]+b[i])
for i in range(n-1,0,-1):
  if ati[i]<k:
    x=i
    break
else:
  x=0
for i in range(x,0,-1):
  for j in range(m):
    if ati[i]+bti[j]<=k:
      if i+j+2>ans:
        ans=i+j+2
    else:
      break
    
print(ans)

Submission status: Wrong Answer

Solution code:
A, B, limit_time = list(map(int ,input().split()))
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

total_time = 0
count = 0

while len(A_list) != 0 or len(B_list) != 0:
  if len(A_list) == 0:
    if total_time + B_list[0] <= limit_time:
      total_time += B_list.pop(0)
      count += 1
  elif len(B_list) == 0:
    if total_time + A_list[0] <= limit_time:
      total_time += A_list.pop(0)
      count += 1
  else:
    if A_list[0] <= B_list[0] and total_time + A_list[0] <= limit_time:
      total_time += A_list.pop(0)
      count += 1
    elif B_list[0] <= A_list[0] and total_time + B_list[0] <= limit_time:
      total_time += B_list.pop(0)
      count += 1
    else:
      break
  
  if total_time >= limit_time:
    break

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N,M,K=map(int,input().split())
As=list(map(int,input().split()))
As=[a for a in accumulate(As) if a <= K]
Bs=list(map(int,input().split()))
Bs=[b for b in accumulate(Bs) if b <= K]
# print(As)
# print(Bs)

anses = []
for ai in range(len(As)-1, 0-1, -1):
    ans = -1
    nokori = K-As[ai]
    for bi in range(len(Bs)-1, 0-1, -1):
        if Bs[bi] <= nokori:
            now = ai+1 + bi+1
            if now > ans:
                ans = now
            elif now == ans:
                continue
            else:
                anses.append(ans)
            print(now, ai+1, bi+1)

if anses == []:
    print(0)
else:
    print(max(anses))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

num_books = 0
remaining_time = K

while True:
    consumption = 0

    if len(A) == 0 and len(B) == 0: break

    if len(A) == 0:
        consumption = B.popleft()
    elif len(B) == 0:
        consumption = A.popleft()
    elif A[0] == B[0]:
        if len(A) <= 1:
            consumption = B.popleft()
        elif len(B) <= 1:
            consumption = A.popleft()
        elif A[1] < B[1]:
            consumption = A.popleft()
        else: 
            consumption = B.popleft()
    elif A[0] < B[0]:
        consumption = A.popleft()
    else:
        consumption = B.popleft()
    # print(consumption)
    
    remaining_time -= consumption
    if remaining_time < 0: break

    num_books += 1

print(num_books)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
AStr = input().split()
BStr = input().split()

A = []
B = []

tmp = 0
for i in AStr:
    tmp += int(i)
    if (tmp > K):
        break
    A.append(int(i))

tmp = 0
for i in BStr:
    tmp += int(i)
    if (tmp > K):
        break
    B.append(int(i))

num = 0
tmp = 0
maxNum = len(A)
if maxNum < len(B):
    maxNum = len(B)

for i in range(len(A)+1):
    num = i
    tmp = 0
    if i != 0:
        tmp += A[i-1]

    for k in B:
        tmp += k
        if (tmp > K):
            if maxNum < num:
                maxNum = num
            continue
        num += 1

print(num)

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()))
cnt=0
na = 0
mb = 0
while k>=0:
    if na >= n and mb>=m:
        cnt+=1
        break
    elif na >= n:
        k-=b[mb]
        mb+=1
        cnt+=1
    elif mb >= m:
        k-=a[na]
        na+=1
        cnt+=1
    elif a[na]>=b[mb]:
        k-=b[mb]
        mb+=1
        cnt+=1
    else:
        k-=a[na]
        na+=1
        cnt+=1

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

C = []
while len(A) != 0 or len(B) != 0:
  if len(A) == 0:
    C.append(B.pop(0))
    continue
  if len(B) == 0:
    C.append(A.pop(0))
    continue
  if A[0] < B[0]:
    C.append(A.pop(0))
  else:
    C.append(B.pop(0))

s = 0
for i in range(n+m):
  s += C[i]
  if s > k:
    print(i)
    quit()
print(n+m)

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

if A[0] > K and B[0] > K:
  print(0)
  
elif sum(A) + sum(B) < K:
  print(N + M)
  
else:
  time = 0
  ans = 0
  for i in range(N + M):
  
    if len(A) == 0 and len(B) == 0:
      break
    elif len(A) == 0:
      time = time + B[0]
      B.pop(0)
    elif len(B) == 0:
      time = time + A[0]
      A.pop(0)
    else:
      if A[0] < B[0]:
        time = time + A[0]
        A.pop(0)
      else:
        time = time + B[0]
        B.pop(0)
  
    if K < time:
      break
    
    ans = ans + 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()))
a.append(10**9)
b.append(10**9)
# k分以内
ans=0
i=0
while True:
    if a[0]>b[0]:
        ans+=b.pop(0)
    else:
        ans+=a.pop(0)
        
    if ans>k:
        print(i)
        quit()
    i+=1

Submission status: Wrong Answer

Solution code:
n,m,k=list(map(int,input().split()))
A=list(map(int,input().split())) + [10**9+1]
B=list(map(int,input().split())) + [10**9+1]
time,ans = 0,0
a_idx,b_idx=0,0

while time <= k and (a_idx != n or b_idx != m):
  if A[a_idx] <= B[b_idx] and a_idx < n:
    time += A[a_idx]
    a_idx += 1
    ans += 1
  elif A[a_idx] > B[b_idx] and b_idx < m:
    time += B[b_idx]
    b_idx += 1
    ans += 1
    
if time > k:
  print(ans-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
def aaa():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = []
    for i,j in zip(a,b):
        c.append(i)
        c.append(j)
    c = sorted(c)
    d = 0
    e = 0
    for i in c:
        if i+e < k:
            e += i
            d += 1
        else:
            return d
    return n + m
nnn = aaa()
print(nnn)

Submission status: Wrong Answer

Solution code:
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
ai = 0
bi = 0
while True:
  if (len(a) != ai and len(b) != bi and a[ai] <= b[bi]) or (len(a) != ai and len(b) == bi):
    k -= a[ai]
    ai += 1
  elif (len(a) != ai and len(b) != bi and a[ai] > b[bi]) or (len(a) == ai and len(b) != bi):
    k -= b[bi]
    bi += 1
  else:
    break
  if k < 0:
    break
  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()))
A.append(10**10)
B.append(10**10)

sig_a = 0
sig_b = 0
ans = 0
for i in range(N+M):
  if A[sig_a] >= B[sig_b]:
    ans += B[sig_b]
    sig_b += 1
  else:
    ans += A[sig_a]
    sig_a += 1
  if ans > K:
    print(i)
    break
    
if ans <= K:
  print(N+M)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba

def run():
    N, M, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))
    B = list(map(int, sysread().split()))

    A_sum = [0]
    for a in A:
        A_sum.append(A_sum[-1] + a)
    B_sum = [0]
    for b in B:
        B_sum.append(B_sum[-1] + b)
    #print(A_sum, B_sum)

    max_val = 0
    for i, a in enumerate(A_sum):
        idx = bisect.bisect_left(B_sum, K-a)
        if idx < len(B_sum) and B_sum[idx] == K-a:
            idx+=1
        max_val = max(max_val, idx+i-1)
        #print(i, idx)
    print(max_val)



    ret = 0
    time = 0


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
time = 0
count = 0
while time < K:
    if len(A) > 0 and len(B) > 0:
        if A[0] < B[0]:
            time += A.pop(0)
            count += 1
        else:
            time += B.pop(0)
            count += 1
    elif len(A) > 0:
        time = A.pop(0)
        count += 1
    elif len(B) > 0:
        time = B.pop(0)
        count += 1
    else:
        break

if time <= K:
    print(count)
else:
    print(count -1)