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()))
ans = 0
end_a = False
end_b = False

while(True):
    k -= min(a[0], b[0])
    if k >= 0:
        ans += 1
    else:
        break
    if a[0] > b[0]:
        del b[0]
    else:
        del a[0]
    if len(a) == 0:
        a = [1e9+1]
        end_a = True
    if len(b) == 0:
        b = [1e9+1]
        end_b = True
    if end_a and end_b:
        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(' ')))

c = []

while True:
    if len(a) == 0:
        c += b
        break
    elif len(b) == 0:
        c += a
        break
    if a[0] <= b[0]:
        c.append(a[0])
        a.pop(0)
    else:
        c.append(b[0])
        b.pop(0)

k2 = 0
t = 0
for i in c:
    k2 += i
    if k2 > k:
        break
    else:
        t += 1
print(t)

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
Ain = 0
Bin = 0
lenA = len(A)
lenB = len(B)
if(min(min(A),min(B))>K):
    print(0)
    exit()
while time<=K:
    if((lenA!=Ain) and (lenB!=Bin)):
        if(A[Ain]<B[Bin]):
            time+= A[Ain]
            Ain+=1
            count +=1
        elif(A[Ain]>B[Bin]):
            time += B[Bin]
            Bin+=1
            count+=1
    if((lenA==Ain) and (lenB==Bin)):
        break
    elif(lenA==Ain):
        time += B[Bin]
        Bin += 1
        count += 1
    elif(lenB==Bin):
        time += A[Ain]
        Ain += 1
        count += 1
if(time == K):
    print(count)
else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n,m,k = LI()
a = LI()
b = LI()

i=0
j=0
t=0
while(t <= k):
    if(i == n):
        t += b[j]
        j += 1
    elif(j == m):
        t += a[i]
        i += 1
    else:
        if(a[i] < b[j]):
            t += a[i]
            i += 1
        elif(a[i] > b[j]):
            t += b[j]
            j += 1
        else:
            if(i < n - 1 and j < m - 1):
                if(a[i+1] < b[j+1]):
                    t += a[i]
                    i += 1
                else:
                    t += b[j]
                    j += 1
            else:
                t += b[j]
                j += 1


    if(i == n and j == m):
        break

if(t > k):
    print(i + j - 1)
else:
    print(i + j)

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

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

i = 0
j = 0

t = 0
while i < N and j < M:
    if A[i] <= B[j]:
        t += A[i]
        if t > K:
            break
        i += 1
    else:
        t += B[j]
        if t > K:
            break
        j += 1

if t < K:
    while i < N:
        t += A[i]
        if t > K:
            break
        i += 1

    while j < M:
        t += B[j]
        if t > K:
            break
        j += 1

print(i + j)

Submission status: Wrong Answer

Solution code:
A,B,time = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
while time > 0:
    if len(a) > 0 and len(b) > 0:  
        if time >= a[0] and time >= b[0]:
            if a[0] <= b[0]:
                time -= a[0]
                a.pop(0)
                ans += 1
            else:
                time -= b[0]
                b.pop(0)
                ans += 1
        elif time >= a[0]:
            time -= a[0]
            a.pop(0)
            ans += 1
        elif time >= b[0]:
            time -= b[0]
            b.pop(0)
            ans += 1
        else:
            break
    elif len(a) == 0 and len(b) > 0:
        if time >= b[0]:
            time -= b[0]
            b.pop(0)
            ans += 1
        else:
            print(ans)
            exit()
    elif len(a) > 0 and len(b) == 0:
        if time >= a[0]:
            time -= a[0]
            a.pop(0)
            ans += 1
        else:
            print(ans)
            exit()
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

N, M, K = map(int, input().split())
Alist = [0] + list(map(int, input().split()))
Blist = list(map(int, input().split()))

B = [Blist[0]]
for b in Blist[1:]:
    B.append(b + B[-1])


sums = 0
ans = 0
for idx, a in enumerate(Alist):
    sums += a
    if sums > K:
        break
    k = K - sums
    print(k)
    tmp = bisect.bisect_right(B, k)
    ans = max(ans, idx + tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
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()]
    res = 0
    time = 0
    a_ind = 0
    b_ind = 0
    ind = 0
    a_f=False
    b_f = False
    lis = []
    while(len(lis)<(n+m)):
        if(a[a_ind]>b[b_ind]):
            lis.append(b[b_ind])
            b_ind+=1
        else:
            lis.append(a[a_ind])
            a_ind+=1
        if(a_ind>=n):
            for i in range(b_ind,m):
                lis.append(b[i])
            break
        if(b_ind>=m):
            for i in range(a_ind,n):
                lis.append(a[i])
            break
        ind+=1
    for i in range(m+n):
        time+=lis[i]
        if(time==k):
            print(i+1)
            exit()
        if(time>k):
            print(i)
            exit()
    print(m+n)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque


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

    A = deque(A)
    B = deque(B)
    ans = 0
    minute = 0

    total = sum(A) + sum(B)
    if (total <= K):
        print(len(A) + len(B))
        return

    while minute < K or (len(A) > 0 and len(B) > 0):
        AA = 10 ** 9
        BB = 10 ** 9
        if (len(A) > 0):
            AA = A.popleft()
        if len(B) > 0:
            BB = B.popleft()

        minute += min(AA, BB)
        if (minute <= K):
            ans += 1

    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
deskA = list(map(int,input().split()))
deskB = list(map(int,input().split()))
bookcount = 0
time = 0
while time <= k:
    if deskA == [] and deskB == []:
        bookcount += 1
        break
    elif deskB == []:
        t = deskA.pop(0)
    elif deskA == []:
        t = deskB.pop(0)
    elif deskA[0] < deskB[0]:
        t = deskA.pop(0)
    elif deskA[0] > deskB[0]:
        t = deskB.pop(0)
    else:
        t = deskA.pop(0)
    time += t
    bookcount += 1

print(bookcount-1)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

cA = [0] + A.copy()
for i in range(N):
    cA[i+1] += cA[i]

cB = [0] + B.copy()
for i in range(M):
    cB[i+1] += cB[i]

# print(cA, cB)

maxnum = 0
# for cosA in range(0, K+1):
#     cosB = K - cosA
#     indA = bisect_left(cA, cosA)
#     indB = bisect_left(cB, cosB)
#     num = indA + indB
#     if maxnum < num: maxnum = num
# print(maxnum)
for indA, ca in enu(cA):
    if K <= ca: continue
    cosB = K - ca
    indB = bisect_right(cB, cosB) - 1
    num = indA + indB
    if maxnum < num: maxnum = num
print(maxnum)

Submission status: Wrong Answer

Solution code:
N, M, K = map(lambda x: int(x), input().split(" "))
As = list(map(lambda x: int(x), input().split(" ")))
Bs = list(map(lambda x: int(x), input().split(" ")))

result = 0
a_index = len(As)
time = 0
for i in range(len(As)):
    a = As[i]
    if time + a > K:
        a_index = i
        break
    result += 1
    time += a


temp_result = result
b_index = 0

while b_index < len(Bs):
    b = Bs[b_index]
    if time + b > K:
        result = max(temp_result, result)
        break
    b_index += 1
    temp_result += 1
    time += b
result = max(temp_result, result)

for i in reversed(range(a_index)):
    a = As[i]
    time -= a
    temp_result -= 1
    while b_index < len(Bs):
        b = Bs[b_index]
        if time + b > K:
            result = max(temp_result, result)
            break
        b_index += 1
        temp_result += 1
        time += b
result = max(temp_result, result)

print(result)

Submission status: Wrong Answer

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

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


SA, SB = [0]*(N+1), [0]*(M+1)
for i, a in enumerate(A):
    SA[i + 1] = SA[i] + a

for i, b in enumerate(B):
    SB[i + 1] = SB[i] + b

piv = M
ans = 0
flg = False
for i, a in enumerate(SA):
    while SB[piv]+SA[i]>K:
        piv -= 1
        if piv <= 0:
            flg = True
            break
    if flg:
        break
    ans = max(ans, piv+i)
print(ans)

Submission status: Wrong Answer

Solution code:
para_list = list(map(int,input().split(' ')))
a_list = list(map(int,input().split(' ')))
b_list = list(map(int,input().split(' ')))

ans = 0
time_cnt = 0
cnt = 0
while(1):
    if(len(a_list)>=1 and len(b_list)>=1):
        if(a_list[0]<b_list[0]):
            time_cnt += a_list.pop(0)
        else:
            time_cnt += b_list.pop(0)
    elif(len(a_list) >= 1):
        time_cnt += a_list.pop(0)
    elif(len(b_list) >= 1):
        time_cnt += b_list.pop(0)
    else:
        break
    if(time_cnt<=para_list[2]):
        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()))
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 t < k:
        if a[a_i] < b[b_i] and t+a[a_i] <= k:
            c += 1
            t += a[a_i]
            if a_i >= 1:
                a_i -= 1
            else:
                a_i = 0
        elif a[a_i] > b[b_i] and t+b[b_i] <= k:
            c += 1
            t += b[b_i]
            if b_i >= 1:
                b_i -= 1
            else:
                b_i = 0
    else:
        break

print(c)

Submission status: Wrong Answer

Solution code:
import sys
n,m,k=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

counter=0
i=0
j=0
tsun=0
finflag=True
while finflag and i < n and j < m:
    tmpa=alist[i]
    tmpb=blist[j]
    if tsun + min(tmpa,tmpb) > k:
        finflag=False
    else:
        if tmpb >= tmpa:
            i += 1
            tsun += tmpa
        else:
            j += 1
            tsun += tmpb

if not finflag:
    print(i+j)
    sys.exit()

if i == n:
    while True and j < m:
        tmpb=blist[j]
        if tsun + tmpb > k:
            break
        else:
            tsun += tmpb
            j += 1
else:
    while True and i < n:
        tmpa=alist[i]
        if tsun + tmpa > k:
            break
        else:
            tsun += tmpa
            i += 1
print(i+j)

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()]
count = 0

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

Submission status: Wrong Answer

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

    i, j = 0, 0
    time_sum = 0
    ans = 0
    while True:
        if i >= n and j >= m:
            break
        elif i < n and j < m:
            if As[i] <= Bs[j]:
                time_sum += As[i]
                i += 1
            else:
                time_sum += Bs[j]
                j += 1
        elif i >= n and j < m:
            time_sum += Bs[j]
            j += 1
        elif j >= m and i < n:
            time_sum += As[i]
            i += 1
        if time_sum > k:
            break
        ans += 1
        if time_sum == k:
            break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-27 20:55:19 +0900
# LastModified: 2020-06-27 21:19:37 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import deque

def main():
    n, m, k = map(int, input().split())
    a = deque(list(map(int, input().split())))
    b = deque(list(map(int, input().split())))
    cnt = 0
    have = 0
    while k > have:
        if not a and not b:
            break
        elif a and not b:
            have += a.popleft()
            if have > k:
                break
            cnt += 1
        elif not a and b:
            have += b.popleft()
            if have > k:
                break
            cnt += 1
        else:
            if a[0] < b[0]:
                have += a.popleft()
                if have > k:
                    break
                cnt += 1
            else:
                have += b.popleft()
                if have > k:
                    break
                cnt += 1
    print(cnt)


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()))
sa = [0 for _ in range(n)]
sb = [0 for _ in range(m)]
x = 0
for i in range(n):
  x += a[i]
  sa[i] = x
y = 0
for j in range(m):
  y += b[j]
  sb[j] = y
ans = 0
si = -1
for i in range(n):
  if sa[n-1-i] <= k:
    si = n-1-i
    break
if si == -1:
  ej = -1
  for j in range(m):
    if sa[j] >k:
      ej = j
      break
  if ej == -1:
    print(m)
    exit()
  print(ej)
  exit()
else:
  ej = 0
  while True:
    while sa[si]+sb[ej] <= k:
      if ans < si + ej + 2:
        ans = si + ej + 2
      ej += 1
      if ej == m:
        break
    if si == 0 or ej == m:
      break
    else:
      si -= 1
  print(ans)

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M, K = LI()
    A = collections.deque(LI())
    B = collections.deque(LI())

    ans = 0
    while K > 0:
        if A and not B or A and B and A[0] < B[0]:
            if K < A[0]:
                break
            K -= A[0]
            A.popleft()
            ans += 1
        elif B and not A or A and B and A[0] >= B[0]:
            if K < B[0]:
                break
            K -= B[0]
            B.popleft()
            ans += 1

    print(ans)


if __name__ == '__main__':
    resolve()

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()))
ans = 0

for i in range(n-1):
    a[i+1] += a[i]
for i in range(m-1):
    b[i+1] += b[i]
for i in range(n):
    res = k - a[i]
    index = bisect.bisect_right(b, res)
    ans = max(ans, index+i+1)
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()))

cnt = 0
tm = 0 
while True:
    out = 0 
    if As == [] and Bs == []:
        break
    elif As == []:
        out = Bs[0]
        Bs = Bs[1:]
    elif Bs == []:
        out = As[0]
        As = As[1:]
    elif As[0] > Bs[0]:
        out = Bs[0]
        Bs = Bs[1:]
    else:
        out = As[0]
        As = As[1:]
    tm += out
    if k < tm:
        break
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

# t = int(input())
# for _ in range(t):
n, m, k = map(int, input().split())
a = dq(map(int, stdin.readline().split()))
b = dq(map(int, stdin.readline().split()))
# nums = list(map(int, stdin.readline().split()))

tot = 0
count = 0
while tot <= k:
    if tot == k:
        break

    atop = a[0] if a else 10**10
    btop = b[0] if b else 10**10

    # both empty
    if atop == 10**10 and btop == 10**10:
        break
    
    if tot + min(atop, btop) > k:
        break

    if atop < btop:
        tot += a.popleft()
        count += 1
    elif btop < atop:
        tot += b.popleft()
        count += 1
    else:
        rema = True
        for i, j in zip(a, b):
            if i < j:
                rema = True
                break
            elif j < i:
                rema = False
                break
            else:
                pass
        if rema:
            tot += a.popleft()
            count += 1
        else:
            tot += b.popleft()
            count += 1

print(count)

Submission status: Wrong Answer

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

def main():
    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
    while K > 0:
        if a == len(A) and b == len(B):
            break
        elif a == len(A):
            K = K - B[b]
            b += 1
            if K >= 0:
                ans += 1
            else:
                break
        elif b == len(B):
            K = K - A[a]
            a += 1
            if K >= 0:
                ans += 1
            else:
                break
        else:
            if A[a] >= B[b]:
                K = K - B[b]
                b += 1
                if K >= 0:
                    ans += 1
                else:
                    break
            else:
                K = K - A[a]
                a += 1
                if K >= 0:
                    ans += 1
                else:
                    break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect

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

asum = [0]
for a in A:
    asum.append(asum[-1] + a)

bsum = [0]
for b in B:
    bsum.append(bsum[-1] + b)

ans = 0
for i, a in enumerate(asum):
    btime = K - a
    if btime > 0:
        break
    bindex = bisect.bisect_right(bsum, btime)
    ans = max(ans, i + (bindex-1))

print(ans)

Submission status: Wrong Answer

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

ans = 0
t = 0
while(t < K):
    minu = 0
    if len(A) != 0 and len(B) != 0:
        if A[0] < B[0]:
            minu = A[0]
            A.pop(0)
        else:
            minu = B[0]
            B.pop(0)
    elif len(A) != 0 and len(B) == 0:
        minu = A[0]
        A.pop(0)
    elif len(A) == 0 and len(B) != 0:
        minu = B[0]
        B.pop(0)
    else:
        break

    t += minu
    if t <= K:
        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()))
    A.extend(B)
    new = sorted(A)
    
    ans = 0
    total = 0
    for a in new:
        total += a
        if total <= k:
            ans += 1
        else:
            break
    print(ans)
resolve()

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())))
p = A.popleft()
q = B.popleft()
SK = 0
Ans = 0
while SK < K:
    if p <= q:
        SK += p
        Ans += 1
        if A != deque([]):
            p = A.popleft()
        else:
            p = 10**10
    else:
        SK += q
        Ans += 1
        if B != deque([]):
            p = B.popleft()
        else:
            q = 10**10
print(Ans-1)

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

i = 0
j = 0
ans = 0
curSum = 0

while i < len(a) and j < len(b):
  if a[i] <= b[j]:
      if a[i] + curSum <= k:
        curSum += a[i]
        i += 1
        ans += 1
      else:
        break
  else:
    if b[j] + curSum <= k:
      curSum += b[j]
      j += 1
      ans += 1
    else:
      break
  
while i < len(a):
  if a[i] + curSum <= k:
    curSum += a[i]
    i += 1
    ans += 1
  else:
    break
    
while j < len(b):
  if b[j] + curSum <= k:
    curSum += b[j]
    j += 1
    ans += 1
  else:
    break
        
print(ans)

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()))
keikajikan = 0
satusuu = 0

while keikajikan <= k:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        keikajikan = keikajikan + b.pop(0)
    elif len(b) == 0:
        keikajikan = keikajikan + a.pop(0)
    else:
        if a[0] <= b[0]:
            keikajikan = keikajikan + a.pop(0)
        else:
            keikajikan = keikajikan + b.pop(0)
    if keikajikan <= k:
        satusuu = satusuu + 1
print(satusuu)

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

r = 0
while n != 0 and m != 0:
	if a[0] > k and b[0] > k:
		break
	if a[0] < b[0]:
		n -= 1
		k -= a[0]
		a.pop(0)
		r += 1
	elif a[0] >= b[0]:
		m -= 1
		k -= b[0]
		b.pop(0)
		r += 1

while n != 0:
	if a[0] > k:
		break
	n -= 1
	k -= a[0]
	a.pop(0)
	r += 1

while m != 0:
	if b[0] > k:
		break
	m -= 1
	k -= b[0]
	b.pop(0)
	r += 1

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

time = 0
total = 0
while time <= k:
    if len(a) == 0 and len(b) ==0:
        break
    elif len(a) ==0:
        time +=b[0]
        total +=1
        b.remove(b[0])
    elif len(b) == 0:
        time += a[0]
        a.remove(a[0])
        total +=1
    else:
        if a[0] >= b[0]:
            time += a[0]
            a.remove(a[0])
            total +=1
        else:
            time += b[0]
            b.remove(b[0])
            total +=1
            
if time > k:
    total = total-1         
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()))
time = 0
num = 0
while True:
  if time > K:
    print("jikann")
  if len(A) == 0 and len(B) == 0:
    break
  elif len(A) == 0:
    if (K - time) < B[0]:
      break
    time += B[0]  
    num += 1
    del B[0]
  elif len(B) == 0:
    if (K - time) < A[0]:
      break
    num += 1
    time += A[0]
    del A[0]
  elif len(A) != 0 and len(B) != 0:
    if A[0] <= B[0]:
      if (K - time) < A[0]:
        break
      time += A[0]
      num += 1
      del A[0]
    else:
      if (K - time) < B[0]:
        break
      num += 1
      time += B[0]
      del B[0]

print(num)

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc172/abc172_c
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M, K = i2nn()
    A = deque(i2nn())
    B = deque(i2nn())
    t = 0
    n = 0
    while True:
        if A and B:
            u = A.popleft() if A[0] < B[0] else B.popleft()
            if t + u > K:
                break
            t += u
            n += 1
        elif A:
            u = A.popleft()
            if t + u > K:
                break
            t += u
            n += 1
        elif B:
            u = B.popleft()
            if t + u > K:
                break
            t += u
            n += 1
        else:
            break
        
    print(n)
    return

main()

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,B,ans,fa,fb=0,0,0,0,0
while k>=0:
  if fa==0 and fb==0:
    if a[A]<b[B]:
      k-=a[A]
      A+=1
      if A>=n:
        fa+=1
    else:
      k-=b[B]
      B+=1
      if B>=m:
        fb+=1
    ans+=1
  elif fa==0:
    k-=a[A]
    A+=1
    ans+=1
    if A>=n:
      fa+=1
  elif fb==0:
    k-=b[B]
    B+=1
    ans+=1
    if B>=m:
      fb+=1
  else:
    ans+=1
    break
print(ans-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()))
count=0
i,j=0,0
while(True):
    if i<N and j<M:
        if A[i]<=B[j]:
            if K>=A[i]:
                K-=A[i]
                count+=1
                i+=1
            else:break
        else:
            if K>=B[j]:
                K-=B[j]
                count+=1
                j+=1
            else:break
    elif i == N:
        if K >= B[j]:
            K -= B[j]
            count += 1
            j += 1
        else:
            break
    elif j==M:
        if K >= A[i]:
            K -= A[i]
            count += 1
            i += 1
        else:
            break
    if K<0:break
    if i==N and j==M: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()))

sum_minute = 0
ans = 0
while (sum_minute < k) or (a or b):
    if a and b:
        if sum_minute + min(a[0], b[0]) <= k:
            if a[0] <= b[0]:
                sum_minute += a[0]
                del a[0]
                ans += 1
            else:
                sum_minute += b[0]
                del b[0]
                ans += 1
        else:
            break
    elif not a:
        if sum_minute + b[0] <= k:
            sum_minute += b[0]
            del b[0]
            ans += 1
        else:
            break
    elif not b:
        if sum_minute + a[0] <= k:
            sum_minute += a[0]
            del a[0]
            ans += 1
        else:
            break              

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[22]:


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


# In[23]:


ans = 0
minute = 0
while minute < K:
    if len(A) > 0 and len(B) > 0:
        if A[0] >= B[0]:
            t = B.pop(0)

        else:
            t = A.pop(0)
    elif len(A) == 0:
        t = B.pop(0)
    else:
        t = A.pop(0)
    minute += t
    if minute <= K:
        ans += 1
#     print(t, minute, ans)
    if len(A)+len(B) == 0:
        break        
print(ans)


# In[ ]:

Submission status: Wrong Answer

Solution code:
import bisect
import itertools
n, m, k = list(map(int, input().split()))
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

rui_al = list(itertools.accumulate(al))
rui_bl = list(itertools.accumulate(bl))


ans = 0

for i in range(n):
    sum_a = rui_al[i]
    if sum_a >= k:
        continue
    j = bisect.bisect_right(rui_bl, k-sum_a)
    ans = max(ans, i+j+1)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,l=map(int,input().split())
x=[int(n) for n in input().split()]
y=[int(n) for n in input().split()]
c=0
ans=0
while c<l:
    if len(x) and len(y) and x[0]>y[0]:
        c+=y[0]
        ans+=1
        y=y[1:]
    elif len(x) and len(y) and x[0]<y[0]:
        c+=x[0]
        x=x[1:]
        ans+=1
    else:
        if len(x):
            c+=x[0]
            ans+=1
        elif len(y):
            c+=y[0]
            ans+=1
        else:
            break
    if c>=l:
        if c>l:
            ans-=1
        break
print(ans)