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:
from itertools import accumulate
from bisect import bisect_right
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
sum_a = list(accumulate(a))
b = list(map(int,input().split()))
sum_b = list(accumulate(b))
ma = 0
#print(sum_a,sum_b)
for i in range(len(sum_a)):
    x = sum_a[i]
    if k<x:
      index = bisect_right(sum_b,k)
      ma = max(index,ma)
    else:
      k -= x
      index = bisect_right(sum_b,k)
      ma = max(i+1+index,ma)
      k += x
    #  print(x,k,index,ma)
print(ma)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    answer = 0
    if a[0] <= k or b[0] <= k:
        answer = 1
    elif a[0] + b[0] <= k:
        answer = 2
    for i in range(1, n):
        a[i] += a[i - 1]
    if a[-1] <= k:
        answer = n
    for i in range(1, m):
        b[i] += b[i - 1]
    if b[-1] <= k:
        answer = max(answer, m)
    if a[-1] + b[-1] <= k:
        answer = n + m
    else:
        for i in range(n):
            l = bisect_right(b, k - a[i])
            if l == 0 or (l == m and b[l - 1] + a[i] > k):
                continue
            answer = max(answer, i + 1 + l)
    print(answer)


if __name__ == '__main__':
    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()))

sumA = [0] * (N+1)
sumB = [0] * (M+1)
for i in range(N):
    sumA[i+1] = sumA[i] + A[i]
for i in range(M):
    sumB[i+1] = sumB[i] + B[i]

ans = 0
import bisect
for i in range(N+1):
    idx = bisect.bisect_right(sumB,K-sumA[i])
    ans = max(ans,i + idx - 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()))

sumA = [0] * (N+1)
sumB = [0] * (M+1)
for i in range(N):
    sumA[i+1] = sumA[i] + A[i]
for i in range(M):
    sumB[i+1] = sumB[i] + B[i]

ans = 0
import bisect
for i in range(N+1):
    idx = bisect.bisect_left(sumB,K-sumA[i])
    ans = max(ans,i + idx - 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()))
time=0
ai=0
bi=0
for i in range(n+m):
    if bi<m:
        if ai<n:
            if a[ai]<b[bi]:
                if time+a[ai]<=k:
                    time+=a[ai]
                    ai+=1
                else:
                    break
            else:
                if time+b[bi]<=k:
                    time+=b[bi]
                    bi+=1
                else:
                    break
        else:
            if time+b[bi]<=k:
                time+=b[bi]
                bi+=1
            else:
                break
    elif ai<n:
        if time+a[ai]<=k:
            time+=a[ai]
            ai+=1
        else:
            break
print(ai+bi)

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()))
sum_a = list(accumulate(a))
b = list(map(int,input().split()))
sum_b = list(accumulate(b))
ma = 0
#print(sum_a,sum_b)
for i in range(len(sum_a)):
    x = sum_a[i]
    if k<x:
      break
    k -= x
    index = bisect_right(sum_b,k)
    ma = max(i+1+index,ma)
    k += x
  #  print(x,k,index,ma)
print(ma)

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()))
sum_a = list(accumulate(a))
b = list(map(int,input().split()))
sum_b = list(accumulate(b))
ma = 0
print(sum_a,sum_b)
for i in range(len(sum_a)):
    x = sum_a[i]
    if k<x:
      break
    k -= x
    index = bisect_right(sum_b,k)
    ma = max(i+1+index,ma)
    k += x
  #  print(x,k,index,ma)
print(ma)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
lA = [0] + list(map(int, input().split()))
lB = [0] + list(map(int, input().split()))

lC = lA + lB
total_time = sum(lC)
if total_time <= k:
    print(len(lC) - 2)
else:
    for i in range(len(lC)):
        total_time -= lC[-(i+1)]
        if total_time <= k:
            break
    if i+1  > len(lB):
        pA = len(lC) - i - 2
        pB = 0

    else:
        pA = len(lA) - 1
        pB = len(lB) - i - 1
        print('test')
    books = pA + pB
    max_books = books
    #print(books, pA, pB)
    
    for j in range(1, len(lB) - pB):
        pB += 1
        books += 1
        total_time += lB[pB]
        while pA >= 0 and total_time > k:
            pA -= 1
            books -= 1
            if pA > 0:
                total_time -= lA[pA]
            max_books = max(books, max_books)
    print(max_books)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right


def main():
    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]
    answer = 0
    if a[-1] + b[-1] <= k:
        print(n + m)
    else:
        for i in range(n):
            l = bisect_right(b, k - a[i])
            if l == m or (l == 0 and b[l] + a[i] != k):
                continue
            diff = 1 if b[l] + a[i] == k else 0
            answer = max(answer, i + 1 + l + diff)
        print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def main():
    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]
    answer = 0
    if a[-1] + b[-1] <= k:
        print(n + m)
    else:
        for i in range(n):
            l = bisect_left(b, k - a[i])
            if l == m or (l == 0 and b[l] + a[i] != k):
                continue
            diff = 1 if b[l] + a[i] == k else 0
            answer = max(answer, i + 1 + l + diff)
        print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# C - Tsundoku

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

ai = 0
bi = 0
while True:
    if ai < n and k >= a[ai] and (bi >= m or a[ai] < b[bi]):
        k -= a[ai]
        ai += 1
    elif bi < m and k >= b[bi] and (ai >= n or b[bi] < a[ai]):
        k -= b[bi]
        bi += 1
    elif ai < n and bi < m and k >= a[ai] == b[bi]:
        if ai + 1 >= n:
            k -= a[ai]
            ai += 1
        elif bi + 1 >= m:
            k -= b[bi]
            bi += 1
        elif a[ai + 1] < b[bi + 1]:
            k -= a[ai]
            ai += 1
        else:
            k -= b[bi]
            bi += 1
    else:
        break

print(ai + bi)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def main():
    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]
    answer = 0
    for i in range(n):
        l = bisect_left(b, k - a[i])
        if l == m or l == 0:
            continue
        diff = 1 if b[l] == k - a[i] else 0
        answer = max(answer, i + 1 + l + diff)
    print(answer)


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()))
ans = 0
for i in range(n):
    if i == 0:
        continue
    elif a[i]+a[i-1] <= k:
        a[i] += a[i-1]
    else:
        a[i] = k+1
for i in range(m):
    if i == 0:
        continue
    elif b[i] + b[i - 1] <= k:
        b[i] += b[i - 1]
    else:
        b[i] = k + 1
if a[n-1]+b[m-1] <= k:
    ans = n+m
elif a[0]>k and b[0]>k:
    ans = 0
else:
    a.insert(0,0)
    b.insert(0,0)
    bij=0
    ans1 = -1
    for i in range(n+1):
        bx = bij + i - 1
        bij = 0
        if a[i] <= k:
            for j in range(m):
                if k-a[i] >= b[j]:
                    bij = j
                    ans = bij + i

                else:
                    break
            if bx > bij + i:
                ans = bx
                break

        else:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    left = 0
    right = M + 1
    while right - left > 1:
        mid = (right + left) // 2
        if b[mid] > (K - a[i]):
            right = mid
        else:
            left = mid
    res = max(ans, i + left)

print(res)

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()))
sa,sb = [0],[0]
ans = 0
for i in range(n):
    sa.append(sa[i]+a[i])
for i in range(m):
    sb.append(sb[i]+b[i])


for i in range(n+1):
    sai = sa[i]
    x = k-sai
    if x>0:
        ans = max(ans,bisect.bisect_right(sb,x)-1+i)
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()))
An = 0
Bn = 0
g = 0
c = 0
while True :
    if An == len(As):
        g += Bs[Bn]
        c += 1
        Bn += 1 
    elif Bn == len(Bs):
        g += As[An]
        c += 1       
        An += 1
    elif As[An] > Bs[Bn] :
        g += Bs[Bn]
        c += 1
        Bn += 1
    elif As[An] < Bs[Bn]:
        g += As[An]
        c += 1
        An += 1                
    else:
        g += As[An]
        c += 1
        An += 1  
    if g > k :
        c -= 1
        break
    elif An == len(As) and Bn == len(Bs):
        break    
print(c)

Submission status: Wrong Answer

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

cnt = 0
while k > 0:
  if len(la) == 0 and len(lb) == 0:
    break
  elif len(la) == 0:
    if lb[0] <= k:
      k -= lb.pop(0)
      # cnt += 1
    else:
      break
  elif len(lb) == 0:
    if la[0] <= k:
      k -= la.pop(0)
      # cnt += 1
    else:
      break
  else:
    if la[0] < lb[0]:
      k -= la.pop(0)
    else:
      k -= lb.pop(0)
  if k >= 0:
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    acc_A = [0] + list(accumulate(A))
    acc_B = [0] + list(accumulate(B))

    ans = 0
    for i, a in enumerate(acc_A):
        tmp = i
        rest = K - a
        if rest <= 0:
            ans = max(ans, bisect_right(acc_B, K) - 1)
            break
        b_ind = bisect_right(acc_B, rest) - 1
        tmp += b_ind

        ans = max(ans, tmp)
   
    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()))

from itertools import accumulate
import bisect

sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = 0
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue

    time_rest = k - sum_a_list[a_idx]
    b_idx = bisect.bisect_left(sum_b_list,time_rest)
    
    ans = max(ans, a_idx + b_idx)
        
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()))
aa=[0]
bb=[0]
a_sum=0
b_sum=0

for i in range(n):
    if (a_sum+a[i])<=k:
        a_sum+=a[i]
        aa.append(a_sum)
    else:
        break
for i in range(m):
    if (b_sum+b[i])<=k:
        b_sum+=b[i]
        bb.append(b_sum)
    else:
        break

#print(aa)
#print(bb)
cnt=len(bb)-1
for i in range(len(aa)):
    for j in range(cnt,-1,-1):
        if (aa[i]+bb[j])<=k:
            #print(aa[i],bb[j],aa[i]+bb[j])
            cnt=j
            ans=max(cnt,(i+j))
            #print(cnt)
            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()))
time=0
ai=0
bi=0
la=len(a)
lb=len(b)
for i in range(2000000):
    if bi<lb:
        if ai<la:
            if a[ai]<b[bi]:
                if time+a[ai]<=k:
                    time+=a[ai]
                    ai+=1
                else:
                    break
            else:
                if time+b[bi]<=k:
                    time+=b[bi]
                    bi+=1
                else:
                    break
        else:
            if time+b[bi]<=k:
                time+=b[bi]
                bi+=1
            else:
                break
    elif ai<la:
        if time+a[ai]<=k:
            time+=a[ai]
            ai+=1
        else:
            break
    else:
        break
print(ai+bi)

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
ai=0
bi=0
la=len(a)
lb=len(b)
for i in range(200000):
    if bi<lb:
        if ai<la:
            if a[ai]<b[bi]:
                if time+a[ai]<=k:
                    time+=a[ai]
                    ai+=1
                else:
                    break
            else:
                if time+b[bi]<=k:
                    time+=b[bi]
                    bi+=1
                else:
                    break
        else:
            if time+b[bi]<=k:
                time+=b[bi]
                bi+=1
            else:
                break
    elif ai<la:
        if time+a[ai]<=k:
            time+=a[ai]
            ai+=1
        else:
            break
    else:
        break
print(ai+bi)

Submission status: Wrong Answer

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

    total = 0
    for i, a_book in enumerate(a_books):
        if total + a_book <= k:
            total += a_book
            a_books[i] = total
        else:
            a_books = a_books[:i]
            break
            
    answer = 0
    for i, a_time in enumerate(a_books):
        time_left = k - a_time
        if time_left < 0:
            break
        elif time_left == 0:
            answer = max(answer, i+1)
            break
        else:
            for j, b_book in enumerate(b_books):
                if time_left < b_book:
                    answer = max(answer, i+1+j)
                    break
                else:
                    time_left -= b_book
            else:
                answer = max(answer, i+1+m)

    print(answer)


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()))
M = 0
a = 0
b = 0
while M <= 240:
    if A[a] < B[b]:
        M += A[a]
        a += 1
    elif A[a] > B[b]:
        M += B[b]
        b += 1
print(a+b)

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

sum_m = 0
max_ai = -1
for i in range(N):
    if sum_m + A[i] <= K:
        sum_m += A[i]
        max_ai = i
    else:
        break

max_bi = -1
max_count = -2
for j in reversed(range(max_ai + 1)):
    for k in range(max(0, max_bi + 1), M):
        if sum_m + B[k] <= K:
            sum_m += B[k]
            max_bi = k
        else:
            break
    if j + max_bi > max_count:
        max_count = j + max_bi
    
    sum_m -= A[j]

print(max_count + 2)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    a_sum = [0 for x in range(n)]
    b_sum = [0 for x in range(m)]

    a_sum[0] = a[0]
    b_sum[0] = b[0]

    max_counter = 0

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

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

    for i in range(n):
        if a_sum[i] > k:
            break

        for j in range(m - 1, -1, -1):
            if k >= a_sum[i] + b_sum[j] and max_counter < i + j + 2:
                max_counter = i + j + 2
                break
        
    print(max_counter)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########

def resolve():
    n,m,k = mi()
    a = mi()
    b = mi()
    cum_a = create_cum(a,k)
    cum_b = create_cum(b,k)

    res = 0
    for i in range(len(cum_a)):
        val_a = cum_a[i]
        tmp = 0
        for j in range(len(cum_b)):
            val_b = cum_b[j]
            if val_a + val_b <= k:
                tmp = i+1 + j+1    
        res = max(res, tmp)

    print(res)

def create_cum(x,k):
    fval = x[0]
    for i in range(1,len(x)):
        val = fval + x[i]
        if val > k:
            x = x[:i]
            break
        x[i] = val
        fval = x[i]
    return x

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    a_sum = [0 for x in range(n)]
    b_sum = [0 for x in range(m)]

    a_sum[0] = a[0]
    b_sum[0] = b[0]

    max_counter = 0

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

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


    print(a_sum)
    print(b_sum)

    for i in range(n):
        if a_sum[i] > k:
            break

        for j in range(m - 1, -1, -1):
            if k >= a_sum[i] + b_sum[j] and max_counter < i + j + 2:
                max_counter = i + j + 2
                break
        
    print(max_counter)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	A.append(inf)
	B.append(inf)

	ans = 0
	times = 0
	mA = 0
	mB = 0

	while True:
		if times > K:
			print(ans-1)
			sys.exit()

		if A[mA] <= B[mB]:
			times += A[mA]
			mA += 1
		else:
			times += B[mB]
			mB += 1
		ans += 1


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	A.append(inf)
	B.append(inf)

	ans = 0
	times = 0
	mA = 0
	mB = 0

	while True:
		if times > K:
			print(ans-1)
			sys.exit()

		if A[mA] < B[mB]:
			times += A[mA]
			mA += 1
		else:
			times += B[mB]
			mB += 1
		ans += 1


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
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()))
 
times = 0
count = 0
while times <= k:
  if len(a) == 0 and len(b) == 0:
    count = count + 1
    break
  if len(a) == 0:
    times = times + b[0]
    b.popleft()
    count = count + 1
    continue
  if len(b) == 0:
    times = times + a[0]
    a.popleft()
    count = count + 1
    continue
  if a[0] < b[0]:
    times = times + a[0]
    a.popleft()
    count = count + 1
  elif a[0] > b[0]:
    times = times + b[0]
    b.popleft()
    count = count + 1
  else:
    if len(a) == 1 and len(b) == 1:
      times = times + a[0]
      a.popleft()
      count = count + 1
    elif len(a) == 1 and len(b) > 1:
      if b[0] < b[1]:
        times = times + a[0]
        a.popleft()
        count = count + 1
      else:
        times = times + b[0]
        b.popleft()
        count = count + 1
    elif len(a) > 1 and len(b) == 1:
      if a[0] < a[1]:
        times = times + b[0]
        b.popleft()
        count = count + 1
      else:
        times = times + a[0]
        a.popleft()
        count = count + 1
    else:
      if a[1] < b[1]:
        times = times + a[0]
        a.popleft()
        count = count + 1
      else:
        times = times + b[0]
        b.popleft()
        count = count + 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_i = 0
B_i = 0
ans = 0
time = 0
tem_a = 0
while(1):
  #print(A_i,B_i,ans,time,tem_a)
  if K == time:
    break
  if K < time:
    ans -= 1
    break
  if A_i + B_i == N+M:
    break
    
  tem_a = min(A[A_i],B[B_i])
  time += tem_a
  ans += 1
  if A[A_i] == min(A[A_i],B[B_i]):
    A_i += 1
    if A_i == N:
      A.append(10**12)
  else:
    B_i += 1
    if B_i == M:
      B.append(10**12)
    
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, b = [], []
tmp = 0
for i in range(N):
  tmp += A[i]
  a.append(tmp)
tmp = 0
for i in range(M):
  tmp += B[i]
  b.append(tmp)

total = 0
count = []
for i in range(N):
  if a[i] <= K:
    for j in range(M-1, -1, -1):
      total = a[i] + b[j]
      if total <= K:
        count.append((i+1)+(j+1))
        break
if len(count) == 0:
  print(0)
else:
  print(max(count))

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    a_sum = [0 for x in range(n)]
    b_sum = [0 for x in range(m)]

    a_sum[0] = a[0]
    b_sum[0] = b[0]

    max_counter = 0

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

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

    for i in range(n):
        for j in range(m):
            if k >= a_sum[i] + b_sum[j] and max_counter < i + j + 2:
                max_counter = i + j + 2
        
    print(max_counter)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
time=0
ai=0
bi=0
la=len(a)
lb=len(b)
for i in range(200000):
    if bi<lb:
        if ai<la:
            if a[ai]<b[bi]:
                if time+a[ai]<=k:
                    time+=a[ai]
                    ai+=1
                else:
                    break
            else:
                if time+b[bi]<=k:
                    time+=b[bi]
                    bi+=1
                else:
                    break
        else:
            if time+b[bi]<=k:
                time+=b[bi]
                bi+=1
            else:
                break
    elif ai<la:
        if time+a[ai]<=k:
            time+=a[ai]
            ai+=1
        else:
            break
    else:
        break
print(ai+bi)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	sumA = sum(A)
	sumB = sum(B)
	if sumA + sumB <= K:
		print(N+M)
		sys.exit()

	A.append(inf)
	B.append(inf)

	ans = 0
	times = 0
	flg = False

	while True:
		if times > K:
			print(ans-1)
			sys.exit()

		if A[0] < B[0]:
			times += A[0]
			A = A[1:]
		else:
			times += B[0]
			B = B[1:]
		ans += 1


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    a_sum = [a[0]]
    b_sum = [b[0]]

    max_counter = 0

    for i in range(1, n):
        a_sum.append(a[i] + a_sum[i - 1])

    for i in range(1, m):
        b_sum.append(b[i] + b_sum[i - 1])

    for i in range(n):
        for j in range(m):
            if k >= a_sum[i] + b_sum[j] and max_counter < i + j + 2:
                max_counter = i + j + 2
        
    print(max_counter)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

j = m - 1
cost = sum(b)
cnt = m
ans = 0
for i in range(n + 1):
    if j == -1: break
    if i != 0:
        cost += a[i - 1]
        cnt += 1
    while cost > k and j >= 0:
        cost -= b[j]
        cnt -= 1
        j -= 1
    ans = max(cnt, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	A.append(inf)
	B.append(inf)

	sumA = sum(A)
	sumB = sum(B)
	if sumA + sumB <= K:
		print(N+M)
		sys.exit()

	ans = 0
	times = 0

	while True:
		if times > K:
			break

		if A[0] < B[0]:
			times += A[0]
			A = A[1:]
		else:
			times += B[0]
			B = B[1:]
		#print(times)
		ans += 1

	print(ans-1)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[int(j)for j in input().split()]
b=[int(j)for j in input().split()]
from itertools import accumulate
a=[0]+list(accumulate(a))
b=[0]+list(accumulate(b))
ans=0
import bisect
for i,j in enumerate(a):
    if k-j>0:
        idx=bisect.bisect_right(b,k-j)-1
        ans=max(ans,i+idx)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_array = [int(x) for x in input().split()]
b_array = [int(x) for x in input().split()]
res = 0
while k > 0:
    if len(b_array) == 0 and len(a_array):
        break
    elif len(a_array) == 0:
        b = b_array.pop(0)
        k -= b
        if k >= 0:res += 1
    elif len(b_array) == 0:
        a = a_array.pop(0)
        k -= a
        if k >= 0:res += 1
    else:
        if b_array[0] >= a_array[0]:
            a = a_array.pop(0)
            k -= a
            if k >= 0:res += 1
        else:
            b = b_array.pop(0)
            k -= b
            if k >= 0:res += 1
print(res)