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:
i1 = input().split(" ")
n = int(i1[0])
m = int(i1[1])
k = int(i1[2])
i2 = input().split(" ")  # desk A
i3 = input().split(" ")  # desk B

t = 0
at = 0
bt = 0


def isWithinBudget(val, k):
    if k - val < 0:
        return False
    else:
        return True


# def findBestProceeding(param, param1, k ,t ):
#     if len(param) == 0 and len(param1) == 0:
#         return t
#     elif len(param) == 0:
#         val = param1[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param,param1[1:],k-val,t+1)
#         else:
#             return t
#     elif len(param1) == 0:
#         val = param[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param[1:],param1,k-val,t+1)
#         else:
#             return t
#     if param[0] < param1[0]:
#         val = param[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param[1:], param1, k - val, t + 1)
#         else:
#             return t
#     elif param[0] > param1[0]:
#         val = param1[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param, param1[1:], k - val, t + 1)
#         else:
#             return t
#     else: #equal
#         val = param1[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param[1:], param1[1:], k - val, t + 1)
#         else:
#             return t
tie = 0


for i in range(len(i2) + len(i3)):
    if bt >= len(i3) and at >= len(i2):
        break
    elif bt >= len(i3):
        # pick form desk A
        val = int(i2[at])
        at += 1
        
        if tie != 0:
            bt -= tie
            tie = 0
        
        if isWithinBudget(val, k):
            k -= val
            t += 1
        else:
            break
    elif at >= len(i2):
        val = int(i3[bt])
        bt += 1
        
        if tie != 0:
            at -= tie
            tie = 0
        
        if isWithinBudget(val, k):
            k -= val
            t += 1
        else:
            break
    else:
        if int(i3[bt]) > int(i2[at]):
            # pick form desk A
            val = int(i2[at])
            at += 1

            if tie != 0:
                bt -= tie
                tie = 0
            
            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break
        elif int(i3[bt]) == int(i2[at]):
            val = int(i2[at])
            at += 1
            bt += 1
            tie +=1

            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break
        else:
            val = int(i3[bt])
            bt += 1

            if tie != 0:
                at -= tie
                tie = 0
            
            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break

    if k == 0:
        break
print(t)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
Alist = deque()
Blist = deque()
Alist.extend(list(map(int, input().split())))
Blist.extend(list(map(int, input().split())))

ABlist = deque()
book = 0
nm = n+m
while (len(ABlist) <= nm):
    if (len(Alist) == 0):
        ABlist.extend(Blist)
        break
    elif (len(Blist) == 0):
        ABlist.extend(Alist)
        break

    if (Alist[0] < Blist[0]):
        ABlist.append(Alist[0])
        Alist.popleft()
    else:
        ABlist.append(Blist[0])
        Blist.popleft()

print(ABlist)

while (len(ABlist) > 0):
    if (k - ABlist[0] > 0):
        k -= ABlist[0]
        ABlist.popleft()
        book += 1
    else:
        break
print(book)

Submission status: Wrong Answer

Solution code:
trush_a, trush_b, limit_time = list(map(int,input().split()))
total = [0, 0]
desks = [[],[]]

for i in range(2):

    for j in list(map(int,input().split())):
        temp = total[i] + j 
        if temp <= limit_time:
            total[i] += j
            desks[i].append(j)
        else:
            break

# print(desks[0])
# print(desks[1])

if len(desks[0]) > len(desks[1]):
    select = 0
elif len(desks[0]) == len(desks[1]):
    if total[0] < total[1]:
        select = 0
    else:
        select = 1
else:
    select = 1

if select == 0:
    unselect = 1
else:
    unselect = 0

result = len(desks[select])

left_time = limit_time - total[select]

for i in desks[unselect]:
    if left_time >= i:
        result += 1
        left_time -= i
    else:
        break

print(result)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

target = [A_i_list[0], B_i_list[0]]

## とりあえずAだけのパターンをつくり、そこから
## 一個ずつ引いていく

## Aだけ
counter_A = 0
counter_B = 0
sum_A_list = []
sum_B_list = []
sum_A = 0
sum_B = 0

while True:
    sum_A = sum_A + A_i_list[counter_A]
    if sum_A > K:
        break
    sum_A_list.append(sum_A)
    counter_A = counter_A + 1
    if counter_A == N:
        break
# print(sum_A_list)

while True:
    sum_B = sum_B + B_i_list[counter_B]
    if sum_B > K:
        break
    sum_B_list.append(sum_B)
    counter_B = counter_B + 1
    if counter_B == M:
        break
# print(sum_B_list)

result = []
if len(sum_A_list) == 0:
    result_final = len(sum_B_list)
elif len(sum_B_list) == 0:
    result_final = len(sum_A_list)
else:
    for i, sum_A_target in enumerate(sum_A_list):
        # print("==========")
        # print("i:"+ str(i))
        sum_temp = sum_A_target
        for j in range(len(sum_B_list)):
            # print("j:"+ str(j))
            if sum_temp + sum_B_list[j] > K:
                result.append(i+j+1)
                # print(result)
                break
            if j == len(sum_B_list)-1:
                result.append(i+j+2)
                # print(result)
                break
    result_final = max(result)
print(result_final)

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()))
subseqA = [0] # i th element is sum of first i books
subseqB = [0]
for elem in a:
    subseqA.append(subseqA[-1]+elem)
for elem in b:
    subseqB.append(subseqB[-1]+elem)
maxBooks = 0
curABooks = 0
curBBooks = 0
for i in range(N+1):
    if K < subseqA[i]:
        curABooks = i - 1
        maxBooks = i - 1
        break
for i in range(curABooks,-1,-1):
    for j in range(curBBooks,M+1):
        if subseqA[i] + subseqB[j] > K:
            curBBooks = j - 1
            break
    if i + curBBooks > maxBooks:
        maxBooks = i + curBBooks
print(maxBooks)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from decimal import Decimal

def main():
  M, N, K = map(int, input().split())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  spent_time = 0
  count = 0
  AB = A + B
  AB.sort()
  
  while(True):
    if count == M + N:
      break
    temp = AB[count]
    #print(temp, spent_time)
    if spent_time + temp > K:
      break
    spent_time = spent_time + temp
    count += 1
  
  #print('----')
  #print(spent_time)
  print(count)
  
main()

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


N, M, K = map(int, input().split())
dp = [[]]
#A = deque([int(i) for i in input().split()])
#B = deque([int(i) for i in input().split()])
A = [int(i) for i in input().split()]
AA = [0]
B = [int(i) for i in input().split()]
BB = [0]
for i in range(1,N+1):
    AA.append(AA[i-1]+A[i-1])
for i in range(1,M+1):
    BB.append(BB[i-1]+B[i-1])
ans = []
A_idx = 0
B_idx = M

for i in range(N+M+10):
    if(K<=AA[A_idx]+BB[B_idx]):
        if(B_idx>0):
            B_idx -= 1
        if(K>=AA[A_idx]+BB[B_idx]):
            ans.append(A_idx + B_idx)
    elif(K>=AA[A_idx]+BB[B_idx]):
        if(A_idx<N):
            A_idx += 1
        if(K>=AA[A_idx]+BB[B_idx]):
            ans.append(A_idx + B_idx)


print(max(ans))

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
times_a = list(map(int, input().split()))
times_b = list(map(int, input().split()))
read_time = 0
count = 0
while read_time < K:            
    if len(times_a) != 0 and len(times_b) != 0:
        if times_a[0] <= times_b[0] and (read_time + times_a[0]) < K:
            read_time += times_a[0]
            times_a.pop(0)
            count += 1
        else:
            if (read_time + times_b[0]) < K:
                read_time += times_b[0]
                times_b.pop(0)
                count += 1
            else:
                break
    elif len(times_a) == 0 and len(times_b) != 0 and (read_time + times_b[0]) < K:
        #bから
        read_time += times_b[0]
        times_b.pop(0)
        count += 1
    elif len(times_b) == 0 and len(times_a) != 0 and (read_time + times_a[0]) < K:
        # aから
        read_time += times_a[0]
        times_a.pop(0)
        count += 1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
a.append(1000000000)
b.append(1000000000)
nc = 0
mc = 0
cnt = 0
t = 0
while cnt + a[nc] <= k or cnt + b[mc] <= k:
    if a[nc] > b[mc]:
        cnt += b[mc]
        mc += 1
        t += 1
    else:
        cnt += a[nc]
        nc += 1
        t += 1
print(t)

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

a_i = 0
b_i = 0

#print("a_i =",a_i,"/ b_i =",b_i,"/ K =",K)

while( K>0 and (a_i+b_i)<(N+M) ):
  
  if ( a_i < N and b_i < M ):
    if ( A[a_i] <= B[b_i] ):
      K -= A[a_i]
      a_i += 1
    else:
      K -= B[b_i]
      b_i += 1
  else:
    if ( a_i < N ):
      K -= A[a_i]
      a_i += 1
    else:
      K -= B[b_i]
      b_i += 1

  #print("a_i =",a_i,"/ b_i =",b_i,"/ K =",K)


if (K<0):
  print(a_i+b_i-1)
else:
  print(a_i+b_i)

Submission status: Wrong Answer

Solution code:
from bisect import *
def solve():
    ans = 0
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))+[float('inf')]
    B = list(map(int, input().split()))+[float('inf')]
    cumA = [0]*(N+1)
    cumB = [0]*(M+1)
    for i in range(N):
        cumA[i+1] = cumA[i]+A[i]
    for i in range(M):
        cumB[i+1] = cumB[i]+B[i]
    for i in range(N+1):
        rest = K-cumA[i]
        ind = bisect_right(cumB,rest)
        if ind>1 or i>1:
            ans = max(ans,i+ind-1)
        else:
            ans = max(ans,i+ind-1)
    return ans
print(solve())

Submission status: Wrong Answer

Solution code:
import sys
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A_sum = list()
B_sum = list()
sum_a = 0
sum_b = 0
time = 0
num = 0
leng = N + M
for i in range(N):
  sum_a += A[i]
  A_sum.append(sum_a)
for i in range(M):
  sum_b += B[i]
  B_sum.append(sum_b)
ai = 0
bi = 0
sum_a2 = 0
sum_b2 = 0
for _ in range(leng):
  if ai == N and bi == M:
    break
  elif ai == N:
    sum_b2 = B_sum[bi]
    bi += 1
  elif bi == M:
    sum_a2 = A_sum[ai]
    ai += 1
  elif A_sum[ai] <= B_sum[bi]:
    sum_a2 = A_sum[ai]
    ai += 1
  else:
    sum_b2 = B_sum[bi]
    bi += 1
  time = sum_a2 + sum_b2
  if K >= time:
    num += 1
print(num)

Submission status: Wrong Answer

Solution code:
import sys
data = sys.stdin

conversion_data = []
for l in data:
    conversion_data.append([int(i) for i in l.split()])

table_a = conversion_data[1]
table_b = conversion_data[2]

N = conversion_data[0][0]
M = conversion_data[0][1]
limit = conversion_data[0][2]
max = max([N, M])

total_time = 0
position_a = 0
position_b = 0

for i in range(max):
  if position_a <= N - 1:
      a = table_a[position_a]
      if (a + total_time) <= limit:
          total_time += a
          position_a += 1
  
  if position_b <= M - 1:
    b = table_b[position_b]
    if (b + total_time) <= limit:
      total_time += b
      position_b += 1
  
print(position_a + position_b)

Submission status: Wrong Answer

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

N,M,K=(int(x) for x in input().rstrip('\n').split())
As=[int(x) for x in input().rstrip('\n').split()]
Bs=[int(x) for x in input().rstrip('\n').split()]
res = 0
now = 0
now_a = 0
now_b = 0
for i in range(N+M):
  if now_a==len(As):
    if now_b==len(Bs):
      c=2
      break
    else:
      c=0
  elif now_b==len(Bs):
    c=1
  elif As[now_a]!=Bs[now_b]:
    if As[now_a]<Bs[now_b]:
      c=1
    else:
      c=0
  else:
    nex_a=now_a+1
    nex_b=now_b+1
    while 5572>573:
      if nex_a==len(As):
        c=0
        break
      elif nex_b==len(Bs):
        c=1
        break
      else:
        if As[nex_a]<Bs[nex_b]:
          c=1
          break
        elif As[nex_a]>Bs[nex_b]:
          c=0
          break
        else:
          nex_a+=1
          nex_b+=1
  if c == 1:
    now += As[now_a]
    now_a += 1
  elif c>1:
    break
  else:
    now += Bs[now_b]
    now_b += 1
  if now>K:
    break
  res += 1
print(res)

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 = [float('inf')] * 2000000
count = 0

if (sum(a) + sum(b)) <= k:
  print(len(a) + len(b))

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

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
import numpy as np
from itertools import accumulate
AS = np.array([0] + list(accumulate(A)))
BS = np.array([0] + list(accumulate(B)))

ans = 0
for i in range(n+1):
    if AS[i] > k:
        break
    for j in range(ans-i, m+1):
        if AS[i] + BS[j] > k:
            break
        ans = max(ans, i+j)
        
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def is_ok(l, i, key):
    if l[i] >= key:
        return True


def binary_seach(l, key):
    left = -1  # right = 0が条件を満たさない場合もあるので初期値は左端の外
    right = len(l)  # 右端が条件を満たさない場合もあるので初期値は右端の外

    # 汎用的な二分探索アルゴリズム
    while right - left > 1:
        mid = left + (right - left) // 2
        if is_ok(l, mid, key):
            right = mid
        else:
            left = mid

    return right


def main():
    n, m, k = LI()
    a = deque(LI())
    b = deque(LI())
    costs = [float('inf')] * (n + m + 1)
    costs[0] = 0
    for i in range(1, n + m + 1):
        # print(f'{i=}, {a=}, {b=}')
        if len(a) > 0 and (len(b) == 0 or costs[i - 1] + a[0] <= costs[i - 1] + b[0]):
            costs[i] = costs[i - 1] + a.popleft()
        elif len(b) > 0 and (len(a) == 0 or costs[i - 1] + b[0] <= costs[i - 1] + a[0]):
            costs[i] = costs[i - 1] + b.popleft()

    # print(costs)
    ans = binary_seach(costs, k)
    if costs[ans] != k:
        ans -= 1
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M , W = MAP()
A = LIST()
B = LIST()

sa = sum(A)
sb = sum(B)
A.reverse()
C = A + B
# print(C)
ans = 0
left_wa = 0
right_wa = 0


ruiseki = C.copy()
ruiseki = [0] + ruiseki
for i in range(len(ruiseki)-1):
    ruiseki[i+1] = ruiseki[i] + ruiseki[i+1]
# print(ruiseki)
ruiseki = ruiseki + [ruiseki[-1]]
left = 0
# for right in range(1, len(C)+1):
#     ruiseki[left:right]
idx = 0
wa = 0
ans = 0
# print(len(ruiseki))
if sum(A) + sum(B) <= W:
    print(N + M)
    exit()
for right in range(len(A), len(ruiseki)):
    # idx += 1
    # print("right:", right)
    wa = ruiseki[right] - ruiseki[left]
    # if
    while wa > W:
        left += 1
        wa = ruiseki[right] - ruiseki[left]
    if left < len(A):
        tmp = right - left
        # print(tmp)
        ans = max(tmp, ans)
        # print("left, right:", left, right)
    
    else:
        break
    # print("left, right, :", left, right)

print(ans)        






exit()
for right in range(1, N+1):
    # sum(A[left:right])
    right_wa += C[right-1]
    wa = right_wa - left_wa
    if wa <= K:
        while wa <= K:
            if left < N:
                left_wa += C[left]
                wa = right_wa - left_wa
            left += 1
    ans += left
    



exit()
A = deque(A)
B = deque(B)

# C = A + B
cnt = 0
while W >= 0 and cnt != N + M:
    if len(A) != 0 and len(B) != 0:
        a = A[0]
        b = B[0]
        if a <= b:
            W -= a
            A.popleft()
        else:
            W -= b
            B.popleft()
    elif len(A) != 0:
        # a = INF
        a = A.popleft()
        W -= a
    elif len(B) != 0:
        # a = INF
        b = B.popleft()
        W -= b
    # print(W)
    if W >= 0:
        cnt += 1


print(cnt)



# 3 4 240
# 60 90 120
# 80 150 80 150
# 出力例 1

Submission status: Wrong Answer

Solution code:
s = [input() for i in range(3)]
list1 = list(map(int, s[0].split()))
n = list1[0]
m = list1[1]
k = list1[2]
 
list2 = list(map(int, s[1].split()))
list3 = list(map(int, s[2].split()))
 
counter_l1 = 0
counter_l2 = 0
 
for i in range(n+m):
    if counter_l1 < n and counter_l2 < m:
        if list2[counter_l1] < list3[counter_l2]:
            k = k - list2[counter_l1]
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l1 +=1
            continue
        if list2[counter_l1] >= list3[counter_l2]:
            k = k - list3[counter_l2]
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l2 +=1
    else:
        if counter_l1 >= n:
            k = k - list3[counter_l2]
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l2 +=1
        if counter_l2 >= m:
            k = k - list2[counter_l1]
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l1 +=1
print(counter_l1+counter_l2)

Submission status: Wrong Answer

Solution code:
n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
# a = int(input())
# w = list(map(int, input().split()))
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# bc = [list(map(int, input().split())) for i in range(q)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
total = 0
ai = 0
bi = 0
count = 0


def findNext(data, n):
    for i in range(n, len(data)-1):
        if data[n] != data[i]:
            return data[i]
    return data[n]


while total < p:
    if ai < n and bi < m:
        if a[ai] < b[bi]:
            total += a[ai]
            ai += 1
        elif a[ai] > b[bi]:
            total += b[bi]
            bi += 1
        else:
            a_next = findNext(a, ai)
            b_next = findNext(b, bi)
            if a_next < b_next:
                total += a[ai]
                ai += 1
            else:
                total += b[ai]
                bi += 1
    elif ai >= n and bi < m:
        total += b[bi]
        bi += 1
    elif ai < n and bi >= m:
        total += a[ai]
        ai += 1
    else:
        break

    # print(total)
    if total <= p:
        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()))

total = 0
cnt = 0

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

print(cnt-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = deque([int(i) for i in input().split()])
B = deque([int(i) for i in input().split()])
ans = 0
inf = 10**10
a = A.popleft()
b = B.popleft()

while K >= 0:
    if a == inf and b == inf:
        break
    elif a < b:
        K -= a
        if K >= 0:
            ans += 1
        try:
            a = A.popleft()
        except:
            a = inf

    else:
        K -= b
        if K >= 0:
            ans += 1
        try:
            b = B.popleft()
        except:
            b = inf

print(ans)

Submission status: Wrong Answer

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

N, M, K = MI()
A = LI()
B = LI()
C = A.copy()
D = B.copy()
a = N
b = M

for i in range(1, N):
    A[i] += A[i - 1]
    if A[i] > K:
        a = i
        
for i in range(1, M):
    B[i] += B[i - 1]
    
    if B[i] > K:
        b = i
        

ans = max(a, b)


if ans == a:
    tmp = A[a - 1]
    i = 0
    if A[0] > K:
        ans = 0
        
    while True:
        tmp += D[i]
        
        if tmp > K:
            break
        elif tmp == K:
            ans += 1
            break
        
        ans += 1
        i += 1
        
        if i >= len(D):
            break
        
else:
    tmp = B[b - 1]
    j = 0
    
    if B[0] > K:
        ans = 0
    
    while True:
        tmp += C[j] 
        
        if tmp > K:
            break
        elif tmp == K:
            ans += 1
            break
        
        ans += 1
        j += 1
        
        if j >= len(C):
            break
        
print(ans)

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())))
sum = 0
count = 0
while True:
    if len(A) != 0 and len(B) != 0:
        if len(A) == 0 and B[0]+sum <= K:
            sum += B.popleft()
            count += 1
        elif len(B) == 0 and A[0]+sum <= K:
            sum += A.popleft()
            count += 1
        elif A[0] < B[0] and A[0]+sum <= K:
            sum += A.popleft()
            count += 1
        elif A[0] > B[0] and B[0]+sum <= K:
            sum += B.popleft()
            count += 1
        else:
            break
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
s = 0
ans = 0
while True:
  if A == [] and B == []:
    break
  elif A == []:
    s += B[0]
    B.pop(0)
    if s <= k:
      ans += 1
    else:
      break
  elif B == []:
    s += A[0]
    A.pop(0)
    if s < k:
      ans += 1
    else:
      break
  else: 
    if A[0] >= B[0] :
      s += B[0]
      B.pop(0)
      if s <= k:
        ans += 1
      else:
        break
    else :
      s += A[0]
      A.pop(0)
      if s <= k:
        ans += 1
      else:
        break
print(ans)

Submission status: Wrong Answer

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

        sum_A = []
        sum_B = []

        for i in range(N):
                if i==0:
                        if A[i]>K:
                                break
                        else:
                                sum_A.append(A[i])
                else:
                        A[i] += A[i-1]
                        if A[i]<=K:
                                sum_A.append(A[i])
                        else:
                                break

        for i in range(M):
                if i==0:
                        if B[i]>K:
                                break
                        else:
                                sum_B.append(B[i])
                else:
                        B[i] += B[i-1]
                        if B[i]<=K:
                                sum_B.append(B[i])
                        else:
                                break

        max_ij = 0
        for i in range(len(sum_A)):
                for j in range(len(sum_B)):
                                temp = sum_A[i]+sum_B[j]
                                if temp<=K:
                                        max_ij = max(max_ij,i+j+2)
        ans = max_ij

        return int(ans)

if __name__=="__main__":
        ans = main()
        print(ans)

Submission status: Wrong Answer

Solution code:
# = int(input())
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
count = 0
A.append(10**9+1)
B.append(10**9+1)
A.append(10**9+1)
B.append(10**9+1)

ilist = [0]
jlist = [0]
dcount = 0

i = 0
j = 0
while K >= 0:
    if A[i] == B[j]:
        if A[i+1] < B[j+1]:
            count += 1
            K -= A[i]
            if K >= 0:
                i += 1
                ilist.append(1)
                jlist.append(0)
            else:
                check = 1
        else:
            count += 1
            K -= B[j]
            if K >= 0:
                j += 1
                ilist.append(0)
                jlist.append(1)
            else:
                check = 2
    elif A[i] < B[j]:
        count += 1
        K -= A[i]
        if K >= 0:
            i += 1
            ilist.append(1)
            jlist.append(0)
        else:
            check = 1
    else:
        count += 1
        K -= B[j]
        if K >= 0:
            j += 1
            ilist.append(0)
            jlist.append(1)
        else:
            check = 2

if check == 1:
    K += A[i]
else:
    K += B[j]

if ilist[-1] == 1:
    K += A[i-1]
    print(K)
    while K >= 0:
        if B[j] <= K:
            K -= B[j]
            j += 1
            dcount += 1
        else:
            break
if jlist[-1] == 1:
    K += B[j-1]
    while K >= 0:
        if A[i] <= K:
            K -= A[i]
            i += 1
            dcount += 1
        else:
            break

if dcount >= 2:
    print(dcount+count-2)
else:
    print(count-1)