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

cnt=0
while K >= 0:
  if (len(A) == 0 and len(B) == 0):
    break
  if ((len(A) > 0) and (len(B) == 0 or A[0] < B[0])):
    if A[0] > K:
      break
    K = K - A.pop(0)
    cnt += 1
  elif ((len(B) > 0) and (len(A) == 0 or A[0] >= B[0])):
    if B[0] > K:
      break
    K = K - B.pop(0)
    cnt += 1
print(cnt)

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)
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 = list(map(int, input().strip().split()))
b_list = list(map(int, input().strip().split()))

out, t, i, j = 0 , 0, 0, 0
while t <= k:
    if i == len(a_list) and j == len(b_list):
        out += 1
        break

    a_n = a_list[i] if i < len(a_list) else 10 ** 10
    b_n = b_list[j] if j < len(b_list) else 10 ** 10
    if a_n <= b_n:
        t += a_n
        i += 1
        out += 1
    else:
        t += b_n
        j += 1
        out += 1

print(out - 1)

Submission status: Wrong Answer

Solution code:
def totalCheck(A,K):
  total = 0
  counter = 0
  tem = 0
  for i in A:
    tem += i
    if tem <= K:
      total += i
      counter += 1
    else:
      del A[counter:]
  return A

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

A = totalCheck(A,K)
B = totalCheck(B,K)

max = 0
time = 0
for i in range(len(A)):
  total = i + 1
  time += A[i]
  timec = time
  for j in range(len(B)):
    timec += B[j]
    if timec <= K:
      total += 1
    else:
      break
  if total > max:
    max = total
print(max)

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)

lst = []

i = 0
j = 0
while(i < N or j < M):
    if A[i] > B[j]:
        lst.append(B[j])
        j += 1
    else:
        lst.append(A[i])
        i += 1
            
ans = 0
for elem in lst:
    K -= elem
    ans += 1
    if K < 0:
        ans -= 1
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K=[int(N) for N in input().split()]
A=[int(A) for A in input().split()]
B=[int(B) for B in input().split()]
k=0
while K>0:
    if A and B:
        if A[0]>B[0]:
            K-=B[0]
            k+=1
            del B[0]
        else:
            K -= A[0]
            k += 1
            del A[0]
    elif A:
        K-=A[0]
        k+=1
        del A[0]
    elif B:
        K -= B[0]
        k += 1
        del B[0]
    else:
        break
if K==0:
    print(k)
else:
    print(k-1)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
A = [0]*(N+1)
B = [0]*(M+1)
for i in range(N):
    A[i+1] = A[i] + a[i] 
for i in range(M):
    B[i+1] = B[i] + b[i] 

possible = [0]
for i in range(N+1):
    ans = i
    nokori = K - A[i]
    if nokori <= 0:
        break
    else:
        j = bisect.bisect_right(B,nokori)
        ans += j-1
        possible.append(ans)

print(max(possible))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
it = 200000

k = 0
count = 0
select = list()
for i in range(it):
  if len(A) == 0 and len(B) == 0:
    break
  elif len(A) == 0:
    # Bの本のみ
    select = B
  elif len(B) == 0:
    # Aの本のみ
    select = A
  elif A[0] <= B[0]:
    # BよりもAの方が早く読める(同じも含む)
    select = A
  elif A[0] > B[0]:
    select = B
  k += select[0]
  if k <= K:
    count += 1
  else:
    break
  select.pop(0)
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()))

cnt = 0
ans = 0
for i in range(n+m):
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        cnt += b.pop(0)
        if cnt > k:
            break
    elif len(b) == 0:
        cnt += a.pop(0)
        if cnt > k:
            break
    else:
        if a[0] >= b[0]:
            cnt += b.pop(0)
            if cnt > k:
                break
        else:
            cnt += a.pop(0)
            if cnt > k:
                break
    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()))
n = N + M
count = 0

for i in range(n):
    try:
        if A[i] <= K:
            K = K - A[i]
            count += 1
        else:
            break
    except:
        pass

    try:
        if B[i] <= K:
            K = K - B[i]
            count += 1
        else:
            break
    except:
        pass
    
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
m=0
i=len(a)-1
j=len(b)-1
while m<=k:
    if i>=0 and j>=0:
        if a[i]>=b[j]:
            ans+=1
            i=i-1
        else:
            ans+=1
            j=j-1
    elif i<=-1 and j>=0:
        ans+=1
        j=j-1
    elif i>=0 and j<=-1:
        ans+=1
        i=i-1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    a = list(map(int, lines[1].strip().split(' ')))
    b = list(map(int, lines[2].strip().split(' ')))
    c_max = 0
    c = 0
    s = 0
    for q in b:
        s += q
        if s > k:
            break
        c += 1
    c_max = max(c, c_max)
    s = 0
    c = 0
    for p in a:
        s += p
        c += 1
        if s > k:
            break
        sb = s
        cb = c
        for q in b:
            sb += q
            if sb > k:
                break
            cb += 1
        if c_max > cb:
            break
        c_max = max(cb, c_max)

    print(c_max)

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

an = 0
bn = 0
time = 0
count = 0

for _ in range(10**6):
    if a[an] < b[bn]:
        time += a[an]
        if an < n-1:
             an += 1
    else:
        time += b[bn]
        if bn < m-1:
            bn += 1
    if time <= k:
        count += 1
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,m,k = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]
ta = 0
tb = 0
sum = 0
ans = 0
while True:
    if ta < n and tb < m:
        if a[ta] <= b[tb]:
            sum += a[ta]
            ta += 1
            if sum > k:
                break
            ans += 1
        else:
            sum += b[tb]
            tb += 1
            if sum > k:
                break
            ans += 1
    elif ta >= n and tb < m:
        sum += b[tb]
        tb += 1
        if sum > k:
            break
        ans += 1
    elif ta < n and tb >= m:
        sum += a[ta]
        ta += 1
        if sum > k:
            break
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

time = 0
cnt = 0
while time < K :
    if len(al) >= 1 and len(bl) >= 1:
        if al[0] <= bl[0]:
            time += al[0]
            al.popleft()
        else:
            time += bl[0]
            bl.popleft()
    elif len(al) >= 1:
        time += al[0]
        al.popleft()
    elif len(bl) >= 1:
        time += bl[0]
        bl.popleft()
    else:
        pass
    cnt += 1

if len(al) == len(bl) == 0:
    print(N + M)
else:
    print(cnt-1)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

time = 0
count = 0

a = deque(a)
b = deque(b)

while time <= k:
    if len(a) == 0 and len(b) == 0:
        break
    if len(a) == 0:
        mi = b.popleft()
    elif len(b) == 0:
        mi = a.popleft()
    elif a[0] <= b[0]:
        mi = a.popleft()
    else:
        mi = b.popleft()
    if (time+mi) <= k:
        time += mi
        count += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
def readInt():
    return list(map(int, input().split()))
    
n,m,k = readInt()
a = readInt()
b = readInt()
i = 0
j = 0
t = 0
judge = True
ans = 0
while(t+a[i]<=k or t+b[j]<=k):
    if i < n and j < m:
        if a[i] < b[j]:
            t += a[i]
            if i < n-1: i += 1
        else:
            t += b[j]
            if j < m-1: j += 1
    elif i < n and j >= m:
        t += a[i]
        if i < n-1: i += 1
    elif i >= n and j < m:
        t += b[j]
        if j < m-1: j += 1
    else: break
    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()))

ni = 0
mi = 0
ans = 0

for i in range(n+m):
  if n == ni and m == mi:
    break
  elif n == ni:
    ans += b[mi]
    mi += 1
  elif m == mi:
    ans += a[ni]
    ni += 1
  elif a[ni] <= b[mi]:
    ans += a[ni]
    ni += 1
  else:
    ans += b[mi]
    mi += 1

  if ans > k:
    break

cal = ni + mi
if n != ni or m != mi:
  cal -= 1
print(cal)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate


def binary(N,T):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        if T < b[(l + r) // 2]:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r


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

ans = 0
for i, ai in enumerate(a):
    t = k - ai
    if t >= 0:
        j = binary(m, t)
        ans = max(ans, i + j + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ad = deque(a)
ad.append(float('inf'))
bd = deque(b)
bd.append(float('inf'))
count = 0
while True:
    k = k - min(ad[0],bd[0])
    if k < 0 or ad[0] == float('inf') and bd[0] == float('inf'):
        break
    if ad[0] > bd[0]:
        bd.popleft()
    else:
        ad.popleft()
    count += 1
print(count)

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

count=0

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

print(count-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()))
A=0
B=0
ans=0
t=0
for i in range(n+m):
    if A==len(a) :
        t+=b[B]
        if k<t:
            break
        else:
            B+=1
            ans+=1
    elif B==len(b):
        t+=a[A]
        if k<t:
        
            break
        else:
            A+=1
            ans+=1
    else:

        if a[A]>b[B]:
            t+=b[B]
            if k<t:
                break
            else:
                B+=1
                ans+=1
        else:
            t+=a[A]
            if k<t:
            
                break
            else:
                A+=1
                ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque as q
import bisect

N,M,K=map(int,input().split())
As=q(map(int,input().split()))
Bs=q(map(int,input().split()))

s=[0]*(N+M)
c=0
for i in range(N+M):
    if len(As)==0:
        book=Bs.popleft()
    elif len(Bs)==0:
        book=As.popleft()
    else:
        if As[0] < Bs[0]:
            book=As.popleft()
        else:
            book=Bs.popleft()
    c+=book
    s[i]=c
i=bisect.bisect(s,K)
print(i)

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()))
r=0
t=0
m_i=0
n_i=0
m+=-1
n+=-1
for i in range(m+n+2):
  #print(n_i)
  a_i=a[n_i]
  b_i=b[m_i]
  if ((a_i>b_i and m_i <m) or n_i == n):
    m_i+=1
    t+=b_i
    m_i=min(m_i,m)
  else:
    n_i+=1
    t+=a_i
    n_i=min(n_i,n)
  if t>k:
    break
  r+=1
print(r)

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

cnt = 0
time = 0
a = A.popleft()
b = B.popleft()

while time <= K:
    if a == b == 10**9 + 1:
        break

    if a < b:
        time += a
        try:
            a = A.popleft()
        except:
            a = 10**9 + 1
    else:
        time += b
        try:
            b = B.popleft()
        except:
            b = 10**9 + 1

    if time > K:
        break

    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  A.append(10**9+1)
  B.append(10**9+1)
  ans=0
  a=0
  b=0
  while k>0 and (a<n or b<m):
    if A[a]<=B[b]:
      k-=A[a]
      a+=1
    else:
      k-=B[b]
      b+=1

    if k>=0:
      ans+=1
    else:
      break

  print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = list(map(int, input().split()))
    INF = 1e+10
    A = [INF, ] + list(map(int, input().split()))[::-1]
    B = [INF, ] + list(map(int, input().split()))[::-1]
    a = A.pop()
    b = B.pop()
    s = 0
    ans = 0
    while s <= k:
        if a == b == INF:
            break
        if a <= b:
            s += a
            a = A.pop()
        else:
            s += b
            b = B.pop()
        ans += 1

    else:
        ans -= 1
    print(ans)
if __name__ == '__main__':
    main()

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

C = deque()
time = 0

while len(A) > 0 and len(B) > 0:
  if A[0] >= B[0]:
    C.append(B[0])
    B.popleft()
  else:
    C.append(A[0])
    A.popleft()

while len(A) > 0:
  C.append(A[0])
  A.popleft()
  
while len(B) > 0:
  C.append(B[0])
  B.popleft()
  
count = 0
for c in C:
  if c + time <= K:
    count += 1
    time += c

print(count)

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 = list(reversed(A))
B = list(reversed(B))

total = 0
while K>0 and len(A)+len(B)>0:
  if len(A)==0:
    if B[-1]<=K:
      K -= B.pop()
      total += 1
      continue
    else:
      break
  elif len(B)==0:
    if A[-1]<=K:
      K -= A.pop()
      total += 1
      continue
    else:
      break
  elif min(A[-1],B[-1])<=K:
    if A[-1]<B[-1]:
      K -= A.pop()
    else:
      K -= B.pop()
    total += 1
    continue
  else:
    break
    
print(total)

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()))
AB = 0
A.append(1000000001)
B.append(1000000001)

a = 0
b = 0
x = -1

while K >= AB:
    if A[a] < B[b]:
        AB += A[a]
        a += 1
        x +=1
    else:
        AB += B[b]
        b += 1
        x +=1
print(x)

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())))
cnt = 0
t = 0
ae = True
be = True
ai = 10**9 + 1
bi = 10**9 + 1
while t <= k:
    if len(a) != 0:
        ai = a.popleft()
    else:
        ae = False
    if len(b) != 0:
        bi = b.popleft()
    else:
        be = False

    if ai <= bi:
        if ai != (10**9 + 1):
            t += ai
        if be:
            b .appendleft(bi)
    else:
        if bi != (10**9 + 1):
            t += bi
        if ae:
            a.appendleft(ai)
    if ae == False and be == False:
        break
    if t <= k:
        cnt += 1
    ai = 10**9 + 1
    bi = 10**9 + 1
print(cnt)

Submission status: Wrong Answer

Solution code:
input_list = input().split(" ")
n = int(input_list[0])
m = int(input_list[1])
k = int(input_list[2])
con1 = n >= 1 and n <= 200000
con2 = m >= 1 and m <= 200000
con3 = k >= 1 and k <= 1000000000
lista = list()
listb = list()
result = 0
if con1 == True and con2 == True and con3 == True:
    lista = input().split(" ")
    listb = input().split(" ")
    for i in lista:
        if int(i) <= k:
            k = k - int(i)
            result = result + 1
        else:
            continue
    for i in listb:
        if int(i) <= k and k > 0:
            k = k - int(i)
            result = result + 1
        else:
            continue
    print(result)
else:
    print()

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 = 0
a = a[::-1]
b = b[::-1]
a_i = n-1
b_i = m-1
t = 0
for i in range(n+m):
    if a_i < 0 and b_i >= 0:
        if t+b[b_i] <= k:
            c += 1
            t += b[b_i]
            b_i -= 1
    elif b_i < 0 and a_i >= 0:
        if t+a[a_i] <= k:
            c += 1
            t += a[a_i]
            a_i -= 1
    elif a_i < 0 and b_i < 0:
        break
    elif t < k:
        if a[a_i] < b[b_i] and t+a[a_i] <= k:
            c += 1
            t += a[a_i]
            a_i -= 1
        elif a[a_i] > b[b_i] and t+b[b_i] <= k:
            c += 1
            t += b[b_i]
            b_i -= 1
    else:
        break

print(c)

Submission status: Wrong Answer

Solution code:
nmk = input().split(" ")
nv = [int(i) for i in input().split(" ")]
mv = [int(i) for i in input().split(" ")]

buf = 0
nv_i = 0
mv_i = 0
c = 0

while True:
  nv_i = min(nv_i, int(nmk[0])-1)
  mv_i = min(mv_i, int(nmk[1])-1)
  
  if nv[nv_i] < mv[mv_i]:
    chace = nv[nv_i]
    nv_i += 1
  else:
    chace = mv[mv_i]
    mv_i += 1
    
  if int(nmk[2]) > buf+chace:
    buf += chace
    c+=1
  else:
    break
print(c)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

#累積和を取って片方を全探索、もう片方を二分探索


n,m,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))
lst2 = list(map(int,readline().split()))

def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
lst3 = cumsum(lst1)
lst4 = cumsum(lst2)


ans = 0
for i in range(n):
    res = k-lst3[i]
    if res < 0:
        break
    res2 = bisect.bisect_right(lst4,res)
    ans = max(ans,i+1+res2)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, list(input().split())))
b = list(map(int, list(input().split())))
t = 0
c = 0
while c < n+m:
    if len(b) == 0:
        t = t + a[0]
        a.pop(0)
        if t <= k:
            c = c + 1
        else:
            break
    elif len(a) == 0:
        t = t + b[0]
        b.pop(0)
        if t <= k:
            c = c + 1
        else:
            break
    elif a[0] <= b[0]:
        t = t + a[0]
        a.pop(0)
        if t <= k:
            c = c + 1
        else:
            break
    elif a[0] > b[0]:
        t = t + b[0]
        b.pop(0)
        if t <= k:
            c = c + 1
        else:
            break
print(c)

Submission status: Wrong Answer

Solution code:
R = lambda: map(int, input().split())
*_, k = R()
k += 1
a = R(), R()
x = [next(y) for y in a]
m = min(x)
r = 0
while m < k:
  r += 1
  i = x.index(m)
  x[i] = next(a[i], k)
  k -= m
  m = min(x)
print(r)

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
readTime = 0

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = list(accumulate(A))
b = list(accumulate(B))

ans = 0
for i in range(N):
    tmp = a[i]
    if tmp <= K:
        j = bisect_right(b, K-tmp)
        ans = max(ans, i+j+1)
print(ans)

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()]
lA = len(A)
lB = len(B)
a_i=0
b_i=0
cnt = 0
t = 0
while(k > t):
    if(lA==a_i and lB==b_i):
        break
    if(lA==a_i):
        t += B[b_i]
        b_i += 1
        cnt += 1
        continue
    elif(lB==b_i):
        t += A[a_i]
        a_i += 1
        cnt += 1
        continue
    else:
        if(A[a_i] > B[b_i]):
            now = B[b_i]
            b_i += 1
        else:
            now = A[a_i]
            a_i += 1
        t += now
        cnt += 1

if(t > k):
    cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import heapq
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    j  =  a+b
    heapq.heapify(j)
    time = 0
    res = 0
    while(len(j)>0):
        time += heapq.heappop(j)
        if(time > k):
            break
        res+=1
    print(res)






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()))
a = A[0]
max = 0
for i in range(1,N):
    a += A[i]
    A[i] = a
    if a <= K:
        max = i+1
b = B[0]
if max >= 1:
    L = K-A[max-1]
else:
    L = K
m = 0
for i in range(1,M):
    b += B[i]
    B[i] = b
    if b <= L:
        m = i+1
ans = max+m
if max ==0 and m == 0:
    print(0)
else:
    while(max > 0 and m<M):
        max -= 1
        L = K-A[max-1]
        if m == 0:
            if B[0] <= L:
                m = 1
        if m >= 1:
            while(m<=M and B[m-1]<=L):
                m += 1
        if max + m > ans:
            ans = max+m
    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+1)
b.append(10**9+1)
rest=k
ans=-1
ai=0
bi=0
while rest>=0 and ai+bi<n+m:
    ans+=1
    if a[ai]<=b[bi]:
        rest-=a[ai]
        ai+=1
    else:
        rest-=b[bi]
        bi+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
from bisect import bisect

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
R_A = deque()
R_A.append(0)
i = 0
while i < N:
  R_A.append(R_A[-1]+A[i])
  i += 1 
B = list(map(int, input().split()))
R_B = deque()
R_B.append(0)
i = 0
while i < M:
  R_B.append(R_B[-1]+B[i])
  i += 1 
ans = 0
i = 1
while i <= N:
  m = K - R_A[i]
  if m < 0:
    break
  idx = bisect(R_B, m)
  ans = max(ans, i+idx-1)
  i += 1
print(ans)

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.append(2000000001)
A.append(2000000001)
B.append(2000000001)
B.append(2000000001)
a=0
b=0
count=0
time=0
while True:
    if A[a]+A[a+1]<B[b]+B[b+1]:
        time+=A[a]
        a+=1
        if time>K:
            break
        else:
            count+=1
    else:
        time+=B[b]
        b+=1
        if time>K:
            break
        else:
            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()))

init = 0
init2 = 0
s = 0
for i in range(n):
  if s + a[i] <= k:
    s += a[i]
    init += 1

k2 = k - s
for i in range(m):
  if s + b[i] <= k:
    s += b[i]
    init2 += 1

max_ = init+init2
while init-1 > 0:
  s -= a[init-1]
  init -= 1
  for i in range(init2, m):
    if s + b[i] <= k:
      s += b[i]
      init2 += 1
  max_ = max(max_, init+init2)
print(max_)

Submission status: Wrong Answer

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

desk_A = list(map(int, input().split()))
desk_B = list(map(int, input().split()))

i = 0
j = 0
count = 0

while((i < A and j < B) and t > 0):
  if desk_A[i] < desk_B[j]:
    t -= desk_A[i]
    i += 1
    
  else:
    t -= desk_B[j]
    j += 1
    
  count += 1
  
while(i < A and t > 0):
  t -= desk_A[i]
  i += 1
  count += 1
  
while(j < B and t > 0):
  t -= desk_B[j]
  j += 1
  count += 1

if t < 0:
    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()))

ca = 0
cb = 0
count = 0
ea = False
eb = False
while k > 0:
  if ea and eb:
    break
  elif ea:
    if b[cb] <= k:
        k = k - b[cb]
        count += 1
        cb += 1
        if(cb == len(b)):
          eb = True
    else:
      break
  elif eb:
    if a[ca] <= k:
        k = k - a[ca]
        count += 1
        ca += 1
        if(ca == len(a)):
          ea = True
    else:
      break
  else:
    if a[ca] <= b[cb]:
      if a[ca] <= k:
        k = k - a[ca]
        count += 1
        ca += 1
        if(ca == len(a)):
          ea = True
      else:
        break
    else:
      if b[cb] <= k:
        k = k - b[cb]
        count += 1
        cb += 1
        if(cb == len(b)):
          eb = True
      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()))
t = 0
c = 0
while(t<k):
  if a[0] < b[0]:
    t += a.pop(0)
    c+=1
  else:
    t += b.pop(0)
    c+=1
  if a==[]:a.append(10**8)
  if b==[]:b.append(10**8)
  if a[0]==10**8 and b[0]==10**8:
    c+=1
    break  
print(c-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=0

totaltime=sum(a)+sum(b)
if totaltime<=k:
  ans=m+n
else:
  while True:
    if len(a)>0 and len(b)>0:
      if a[0]<b[0]:
        time+=a[0]
        a.pop(0)
        ans+=1
        if time>=k:
          ans-=1
          break
      else:
        time+=b[0]
        b.pop(0)
        ans+=1
        if time>=k:
          ans-=1
          break
    elif len(a)>0:
      time+=a[0]
      a.pop(0)
      ans+=1
      if time>=k or (len(a)==0 and len(b)==0):
        if time>k:
          ans-=1
        break
    else:
      time+=b[0]
      b.pop(0)
      ans+=1
      if time>=k or (len(a)==0 and len(b)==0):
        if time>k:
          ans-=1
        break      
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right as br


def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    tmp = 0
    a = 0
    b = 0
    Sb = [B[0]]
    for i in range(1, m):
        Sb.append(Sb[-1] + B[i])
    Sa = [A[0]]
    for i in range(1, n):
        Sa.append(Sa[-1] + A[i])
    mx = 0
    for j in range(n):
        index = br(Sb, k - Sa[j]) - 1
        tmp = Sa[j] + Sb[index] if index > 0 else Sa[j]
        if tmp <= k:
            mx = max(mx, j + index + 2)
    print(mx)
    return


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

an = 0
bn = 0
n = 0
while K >= 0:
  if an < N and bn < M:
    if A[an] > B[bn]:
      K = K - B[bn]
      bn += 1
    else:
      K = K - A[an]
      an += 1
  elif an < N and bn >= M:
    K = K - A[an]
    an += 1
  elif an >= N and bn < M:
    K = K - B[bn]
    bn += 1
  else:
    print(n)
    exit()
  if K >= 0:
    n += 1
  else:
    print(n)
    exit()

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



Asum=[0]
for i in A:
  Asum.append(Asum[-1]+i)
  if(Asum[-1]>K):break
    
Bsum=[0]
for i in B:
  Bsum.append(Bsum[-1]+i)
  if(Bsum[-1]>K):break

maxval=len(Asum)-1

for i in range(len(Asum)):
  for j in range(len(Bsum)):
    if Asum[-i-1]+Bsum[j]>K:
      maxval=max(maxval,len(Asum)-1-i+j-1)
      break
    elif j==len(Bsum)-1:
      maxval=max(maxval,len(Asum)-1-i+j)
      
print(maxval)