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: Runtime Error

Solution code:
def main():
    N, M, K = map(int, input().split())
    bookA = list(map(int, input().split()))
    bookB = list(map(int, input().split()))
    Ai = 0
    Bi = 0
    C = 0

    while K > 0:
        if Ai - N == 0 and Bi - M == 0:
            break
        if Ai - N == 0:
            K = K - bookB[Bi]
            if K == 0:
                C = C + 1
                break
            elif K < 0:
                break
            C = C + 1
            Bi = Bi + 1
        elif Bi - M == 0:
            K = K - bookB[Bi]
            if K == 0:
                C = C + 1
                break
            elif K < 0:
                break
            C = C + 1
            Ai = Ai + 1
        else:
            if bookA[Ai] < bookB[Bi]:
                K = K - bookA[Ai]
                if K == 0:
                    C = C + 1
                    break
                elif K < 0:
                    break
                C = C + 1
                Ai = Ai + 1
            else:
                K = K - bookB[Bi]
                if K == 0:
                    C = C + 1
                    break
                elif K < 0:
                    break
                C = C + 1
                Bi = Bi + 1
    
    print(C)
    
    

main()

Submission status: Runtime Error

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

sum = 0;
count = 0;
for i in range(len(a)+len(b)):
    while ( sum  < k  ):
        if(len(a) == 0 or a[i] >= b[i]):
            count +=1
            sb = b.pop(0)
            sum += sb
        else:
            count += 1
            sa = a.pop(0)
            sum += sa

if j == count:
    print(count)
else:
    print(count-1)

Submission status: Runtime Error

Solution code:
import sys
import math
import heapq
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n,m,k=get_ints()
a=get_array()
b=get_array()
ab=sum(a)+sum(b)
sumi=0
ans=0
flag=0
while(1):
    i=0
    if a[i]<=b[i]:
        sumi=sumi+a[0]
        a.pop(0)
        if sumi<=k:
            ans=ans+1
        else:
            break
    elif b[i]<a[i]:
        sumi=sumi+b[0]
        b.pop(0)
        if sumi<=k and sumi<=ab:
            ans=ans+1
        else:
            break
    if a==[]:
        flag=1
        break
    elif b==[]:
        flag==2
if flag==1:
    for i in range(len(b)):
        sumi=sumi+b[i]
        if sumi<=k and sumi<=ab:
            ans=ans+1
        else:
            break
elif flag==2:
    for i in range(len(a)):
        sumi=sumi+a[i]
        if sumi<=k and sumi<=ab:
            ans=ans+1
        else:
            break
print(ans)

Submission status: Runtime Error

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

i, j = 0, 0
suma, sumb = 0, 0
flaga, flagb = True, True

while True:
    if i < len(a):
        if k - suma >= a[i]:
            suma += a[i]
            i += 1
        else:
            flaga = False
    else:
        flaga = False

    if j < len(b):
        if k - sumb >= b[j]:
            sumb += b[j]
            j += 1
        else:
            flagb = False
    else:
        flagb = False
    if not flaga:
        if not flagb:
            break

p = max(i, j)
q = min(i, j)


maxbooks = 0
for x in range(p-1, -1, -1):
    for y in range(q-1, -1, -1):
        if sum(a[0:x+1]) + sum(b[0:y+1]) <= k:
            books = x + y + 2
            maxbooks = max(maxbooks, books)
            br = True
            break
    if br:
        break
print(maxbooks)

Submission status: Runtime Error

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

ans = 0
x = 1

if sum(lsa) + sum(lsb) <= k:
    ans = n + m
else:
    while x == 1:
        if len(lsa) == 0:
            if lsb[0] <= k:
                k -= lsb[0]
                ans += 1
                del lsb[0]
            else:
                x = 0
        else:
            if len(lsb) == 0:
                if lsa[0] <= k:
                    k -= lsa[0]
                    ans += 1
                    del lsb[0]
                else:
                    x = 0
            else:
                if min(lsa[0],lsb[0]) <= k:
                    ans += 1
                    if lsa[0] <= lsb[0]:
                        k -= lsa[0]
                        del lsa[0]
                    else:
                        k -= lsb[0]
                        del lsb[0]
                else:
                    x = 0

print(ans)

Submission status: Runtime Error

Solution code:
nmk = input('')
n = int(nmk.split(' ')[0])
m = int(nmk.split(' ')[1])
k = int(nmk.split(' ')[2])

alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

l = (n+m)
t =k

max_read=0

for i in range(2**l):
    bag = ['A']*l
    for j in range(l):
        if ((i>>j)&1):
            bag[l-1-j]='B'
        if bag.count('A') == n:
            break
    time=0
    read=0
    a=0
    b=0
    bag2=[]
    for item in bag:
        if item=='A':
            t = alist[a]
            bag2.append(t)
            time+=t
            a+=1
            if k>=time:
                read+=1
            else:
                break
        else:
            bag2.append(t)
            t = blist[b]
            time+=t
            b+=1
            if k>=time:
                read+=1
            else:
                break

#    print("{} {}/{} {}".format(i,time,k,bag2))

    if max_read < read:
        max_read = read

print(max_read)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')

def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    total = 0
    a_index = 0
    b_index = 0
    is_finish_a = 0
    is_finish_b = 0
    lena = len(A)
    lenb = len(B)
    for i in range(N+M):
        # print("is_finish_a")
        # print(is_finish_a)
        # print(is_finish_b)
        # print(a_index)
        # print(b_index)
        if is_finish_a == 1 and is_finish_b == 1:
            print(a_index+b_index)
            sys.exit()
        if is_finish_a == 0 and is_finish_b == 0 and total + A[a_index] > K and total + B[b_index] > K:
            print(a_index+b_index)
            sys.exit()
            break
        if is_finish_a == 1:
            if total + B[b_index] > K:
                print(a_index+b_index)
                sys.exit()
            else:
                total+=B[b_index]
                b_index+=1
        if is_finish_b == 1:
            if total + A[a_index] > K:
                print(a_index+b_index)
                sys.exit()
            else:
                total+=A[a_index]
                a_index+=1

        if is_finish_a == 0 and is_finish_b == 0 and A[a_index] > B[b_index]:
            total+=B[b_index]
            b_index+=1
            # print("b_index")
            # print(b_index)
            if a_index == lena:
                is_finish_a = 1
        elif is_finish_a == 0 and is_finish_b == 0:
            total+=A[a_index] 
            a_index+=1
            if a_index == lena:
                is_finish_a = 1
            # print("a_index")
            # print(a_index)
    print(a_index+b_index)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std ;

int main()
{
  long N,M,K ;
  cin >> N >> M >> K ;
  long long A[N] ;
  long long B[M] ;
  for(int i = 0 ; i < N ; i++) cin >> A[i] ;
  for(int i = 0 ; i < M ; i++) cin >> B[i] ;
  int TT = 0 ;
  int i = 0 ;
  int j = 0 ;
  int count = 0 ;
  long long time = 0 ;

  while(TT == 0){
    if(i == N && j == M) break ;

    if(i == N){
      time = time + B[j] ;
      if(time > K){
        time = time - B[j] ;
        break ;
      }
      j = j + 1 ;
      count = count + 1 ;
    }
    else if(j == M){
      time = time + A[j] ;
      if(time > K){
        time = time - A[j] ;
        break ;
      }
      i = i + 1 ;
      count = count + 1 ;
    }
    else if(A[i] <= B[j]){
      time = time + A[j] ;
      if(time > K){
        time = time - A[j] ;
        break ;
      }
      i = i + 1 ;
      count = count + 1 ;
    }
    else{
      time = time + B[j] ;
      if(time > K){
        time = time - B[j] ;
        break ;
      }
      j = j + 1 ;
      count = count + 1 ;
    }
  }
  cout << count << endl ;
}

Submission status: Runtime Error

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

    def dfs(n, i, j, k):
        if k >= K or (i == N and j == M):
            return n
        if i < N and A[i] < B[j] and k + A[i] <= K:
            k += A[i]
            l = dfs(n + 1, i + 1, j, k)
        elif j < M and k + B[j] <= K:
            k += B[j]
            l = dfs(n + 1, i, j + 1, k)
        else:
            return n

        return l

    print(dfs(0, 0, 0, 0))

resolve()

Submission status: Runtime Error

Solution code:
m,n,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
len_a = len(a)
len_b = len(b)
i_a = 0
i_b = 0
sum_time = []

while sum(sum_time) <= k:
    if len_a <= i_a and len_b <= i_b:
        break
    elif len_a <= i_a:
        sum_time.append(b.pop())
    elif len_b <= i_b:
        sum_time.append(a.pop())
    elif a[i_a] <= b[i_b]:
        sum_time.append(a[i_a])
        i_a += 1
    else:
        sum_time.append(b[i_b])
        i_b += 1

if sum(sum_time) > k:
    sum_time.pop()

print(len(sum_time))

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(0)
B.append(0)
ans = 0
for i in range(N+1):
  tmp = sum(A[:i])
  if K - tmp < 0:
    berak
  for j in range(M+1):
    tmp += sum(B[:j])
    if K - tmp < 0:
      break
    ans = max(ans, i+j+2)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
from heapq import heapify, heappush, heappop
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_q = deque(a)
    b_q = deque(b)
    i = 0
    l = []
    heapify(l)
    point = 0
    cnt = 0
    aq = a_q.popleft()
    bq = b_q.popleft()
    heappush(l, aq)
    heappush(l, bq)
    if sum(a) + sum(b) <= k:
        print(len(a) + len(b))
    else:
        while point <= k:
            min_l = heappop(l)
            if point + min_l > k:
                print(cnt)
                exit()
            else:
                point += min_l
                cnt += 1
            if min_l == aq:
                if len(a_q) != 0:
                    aq = a_q.popleft()
                    heappush(l, aq)
            else:
                if len(b_q) != 0:
                    bq = b_q.popleft()
                    heappush(l, bq)
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

n, m, k = (int(x) for x in input().split())

n_list = list(map(int, input().split()))
m_list = list(map(int, input().split()))

count = 0

# 全て読み切れる
if(sum(n_list + m_list) <= k) :
    count = n + m
# どこかで時間切れになる
else :
    for i in range(n + m):

        if 0 <= k - n_list[i] :
            k = k - n_list[i]
            count = count + 1

            if 0 <= k - m_list[i] :
                k = k - m_list[i]
                count = count + 1
            else :
                break
        else :
            break

        # if 0 <= k - n_list[i] :
        #     k = k - n_list[i]
        #     count = count + 1
        # else :
        #     break

        # if 0 <= k - m_list[i] :
        #     k = k - m_list[i]
        #     count = count + 1
        # else :
        #     break

print(count)

Submission status: Runtime Error

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

t = 0
pa = 0
pb = 0

while(t < K + 1 ):
    if pa == N and pb == M:
        pa += 1
        break

    if pa == N :
        t += B[pb]
        pb += 1
        continue
    if pb == M :
        t += B[pa]
        pa += 1
        continue

    if(A[pa] < B[pb]):
        t += A[pa]
        pa += 1
    else:
        t += B[pb]
        pb += 1

print(pa + pb -1)

Submission status: Runtime Error

Solution code:
import sys
import math
from bisect import bisect_left
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
def bs(a,n,x): 
    i = bisect_left(a, x) 
    if i<n and a[i] == x:
    	return i
    elif i:
    	return (i-1) 
    else: 
        return -1
n,m,k = MI()
a = LI()
b = LI()
for i in range(1,n):
	a[i]+=a[i-1]
for i in range(1,m):
	b[i]+=b[i-1]
ans = max(bs(a,n,k),bs(b,m,k))+1
for i in range(n):
	if k<a[i]:
		break
	else:
		temp = i+1+bs(b,m,k-a[i])+1
		ans = max(ans,temp)
for j in range(m):
	if k<b[i]:
		break
	else:
		temp = i+1+bs(a,n,k-b[i])+1
print(ans)

Submission status: Runtime Error

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

S = [0]

Sum = 0


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

for j in range(M):
  K = K - B[j]
  if K >= 0:
    Sum += 1
  else:
    if Sum == 0:
      break
    while(K<0):
      i = i - 1
      K = K + A[i]
      Sum = Sum - 1
    Sum += 1
  S.append(Sum)
print(max(S))

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = []
B = []
A = input().split()
B = input().split()
XA = 0
XB = 0
TI = 0
for i in range(N+M):
  if XA == N:
    if (TI + int(B[XB]))<= K:
      TI = TI + int(B[XB])
      XB = XB +1
  elif XB == N:
    if (TI + int(A[XA]))<= K:
      TI = TI + int(A[XA])
      XA = XA +1
  elif int(A[XA]) <= int(B[XB]):
    if (TI + int(A[XA]))<= K:
      TI = TI + int(A[XA])
      XA = XA +1
    else:
      break
  else:
    if (TI + int(B[XB]))<= K:
      TI = TI + int(B[XB])
      XB = XB +1
    else:
      break
print(XA+XB)

Submission status: Runtime Error

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

A_np = np.array(A)
B_np = np.array(B)

C_np = np.append(A_np,B_np)
C_np = np.sort(C_np)
print(C_np)
x = 0
for i in range(len(C_np)):
    if K >= x + C_np[i]:
        x += C_np[i]
        y += 1
    else:
        break
print(y)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))

a_sum=[list_a[0]]
for i in range(1, n):
  sum=list_a[i]+a_sum[i-1]
  a_sum.append(sum)
  
b_sum=[list_b[0]]
for i in range(1, m):
  sum=list_b[i]+b_sum[i-1]
  b_sum.append(sum)
  
ans=[]
if (a_sum[0]>k) & (b_sum[0]>k):
  print(0)
else:
  for i in range(n):
    for j in range(m):
      if a_sum[i]+b_sum[j] <= k:
        key=i+j+2
        if key not in ans:
          ans.append(key)
  print(max(ans))

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = 0
j = 0
count = 0
for i in range(N+1):
	for j in range(M+1):
		if sum(A[:i]) + sum(B[:j]) <= K:
			tmp = i + j
			count = max(tmp, count)
		else:
			break
	if if sum(A[:i]) + sum(B[:j]) > K:
		break
print(count)

Submission status: Runtime Error

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

cnt = 0
cost = 0
for i, x in enumerate(a):
    cost += x
    if cost > k:
        cnt = i
        cost -= x
        break
else:
    for j, y in enumerate(b):
        cost += y
        if cost > k:
            cnt = n + j
            cost -= y
            break
    else:
        cnt = n + m

if cnt <= n:
    i, j = cnt, 0
else:
    i, j = n, cnt - n + 1

ans = cnt
initial = True
while i >= 0 and j < m:
    if i < n and not initial:
        cost -= a[i]
        cnt -= 1
    while cost + b[j] <= k and j < m:
        j += 1
        cnt += 1
        cost += b[j]
    ans = max(cnt, ans)
    i -= 1
    if initial: initial = False

print(ans)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a[i]+a_sum[i])
    if a_sum[i]>1e+9:
        break
for i in range(m):
    b_sum.append(b[i]+b_sum[i])
    if b_sum[i]>1e+9:
        break
        
ans = 0
for i in range(len(b_sum)):
    if a_sum[i]>k:
        break
    time = k - a_sum[i]
    for j in range(len(b_sum)):
        if time<b_sum[j+1]:
            break
    if time>=b_sum[len(b_sum)-1]:
        j = len(b_sum)-1
    ans = max(ans,i+j)
    
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
totalbook = 0
totaltime = 0
for a in range(200000):
    if A[0] <= B[0]:
        tt = A.pop(0)
    else:
        tt = B.pop(0)
    if totaltime + tt <= K:
        totaltime += tt
        totalbook += 1
    else:
        break
print(totalbook)

Submission status: Runtime Error

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    f = [1]*(n+1)
    ans = 1
    for i in range(2, n+1):
        for j in range(i, n+1, i):
            f[j] += 1
        ans += i*f[i]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
f = open('input.txt', 'r')
sys.stdin = f
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ai =0
bi=0
st =0
c = 0
while True:
  if ai == N:
    if bi == M:
      break
    else:
      st += b[bi]
      if st > K:
        break
      bi += 1
      c +=1
  elif bi == M:
    if ai == N:
      break
    else:
      st += a[ai]
      if st > K:
        break
      ai += 1
      c += 1
  elif a[ai] > b[bi]:
    st += b[bi]
    if st > K:
      break
    bi +=1
    c +=1
  elif a[ai] < b[bi]:
    st += a[ai]
    if st > K:
      break
    ai +=1
    c +=1
  elif a[ai] == b[bi]:
    tmpst = st
    tmpc =0
    tmpai = ai
    tmpbi = bi
    while True:
      tmpst +=a[tmpai]
      if tmpai < N-1:
        tmpai+=1
      if tmpbi < M-1:
        tmpbi+=1
      if tmpst > K:
        st += a[ai]
        if st > K:
          print(c)
          exit()
        ai +=1
        c +=1
        #print(c+tmpc,'ja')
        #exit()
      if a[tmpai] > b[tmpbi]:
          st += a[ai]
          if st > K:
              print(c)
              exit()
          ai += 1
          c += 1
          break
      elif a[tmpai] < b[tmpbi]:
          st += b[bi]
          if st > K:
              print(c)
              exit()
          bi += 1
          c += 1
          break
      if tmpai == N-1 and tmpbi == M-1:
          print(N+M)
          exit()
      print(tmpst)
      tmpc += 1
#      print(tmpai, tmpbi)
print(c)

Submission status: Runtime Error

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

read = 0
i, j = 0, 0
while(i<len(a) and j<len(b)):
    if a[i] < b[j]:
        flag = True
    elif a[i] == b[j]:
        q, p = 0, 0
        while((q+i)<len(a) and (p+j)<len(b)):
            q += 1
            p += 1
            if a[q+i] < b[p+j]:
                flag = True
                break
            elif a[q+i] > b[p+j]:
                flag = False
                break
    else:
        flag = False

    if flag:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1
    if k<0:
        break
    read += 1

if k > 0:
    if i==len(a):
        while(j < len(b)):
            k -= b[j]
            j += 1
            if k<0:
                break
            read += 1
    elif j==len(b):
        while(i < len(a)):
            k -= a[i]
            i += 1
            if k<0:
                break
            read += 1

print(read)

Submission status: Runtime Error

Solution code:
#C
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
i = 0
j = 0
for _ in range(n+m):
    # print(i,j,k)
    if n <= i:#
        k -= b[j]
        j += 1
        ans += 1
        continue
    elif n <= j:
        k -= a[i]
        i += 1
        ans += 1
        continue
    if a[i] < b[j]:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1
    if k < 0:
        break
    ans += 1
    if k == 0:
        break
print(ans)

Submission status: Runtime Error

Solution code:
a = input().split()
x = int(input().split())
y = int(input().split())
z = x.append(y)
t = 0
for i in range(len(z)):
  if t > int(a[2]):
    break
  t += sorted(z)[i]
print(t)

Submission status: Runtime Error

Solution code:
from collections import deque
from decimal import Decimal

N, M, K = map(Decimal, input().split())
A = deque(map(Decimal, input().split()))
B = deque(map(Decimal, input().split()))

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

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

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

    if time > K:
        break

    cnt += 1

print(cnt)

Submission status: Runtime Error

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

time = 0
i = 0
j = 0
count = 0

while time <= k:
    if i == len(a) and j == len(b):
        time += k
    elif i == len(a):
        time += b[j]
        if time > k:
            break
        j += 1
        count += 1
    elif j == len(b):
        time += a[i]
        if time > k:
            break
        i += 1
        count += 1
    elif a[i] < b[j]:
        time += a[i]
        if time > k:
            break
        i += 1
        count += 1
    elif a[i] > b[j]:
        time += b[j]
        if time > k:
            break
        j += 1
        count += 1
    elif a[i] == b[j]:
        if a[i+1] > b[j+1]:
            time += b[j]
            if time > k:
                break
            j += 1
            count += 1
        elif a[i+1] < b[j+1]:
            time += a[i]
            if time > k:
                break
            i += 1
            count += 1

print(count)

Submission status: Runtime Error

Solution code:
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    N, M, K = map(int, input().split())

    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    def dfs(n, m, total, count):
        if total > K:
            return count - 1

        if n == N and m == M:
            return count

        if n < N:
            c1 = dfs(n+1, m, total + As[n], count+1)
        else:
            c1 = count

        if m < M:
            c2 = dfs(n, m+1, total + Bs[m], count+1)
        else:
            c2 = count

        return max(c1, c2)

    return dfs(0, 0, 0, 0)


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=0
b=0
t=0
while t<=k:
  if a<=n-1 and b<=m-1:
    if A[a]<B[b]:
      t+=A[a]
      a+=1
    elif A[a]>B[b]:
      t+=B[b]
      b+=1
    else:
      d=1
      d_=1
      while d!=n-a or d_!=m-b:
        if A[a+d]==B[b+d_]:
          d+=1
          d_+=1
        elif A[a+d]<B[b+d_]:
          a_=a
          while t<=k and a<=a_+d:
            t+=A[a]
            a+=1
        elif A[a+d]>B[b+d_]:
          b_=b
          while t<=k and b<=b_+d:
            t+=B[b]
            b+=1
        if d==n-a:
          b_=b
          while t<=k and b_+d:
            t+=B[b]
            b+=1
        elif d_==m-b:
          a_=a
          while t<=k and a<=a_+d_:
            t+=A[a]
            a+=1
  elif a>=n and b<=m-1:
    t+=B[b]
    b+=1
  elif b>=m and a<=n-1:
    t+=A[a]
    a+=1
  else:
    print(n+m)
    exit()
print(a+b-1)

Submission status: Runtime Error

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

S = [0]

Sum = 0


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

for j in range(M):
  K = K - B[j]
  if K > 0:
    Sum += 1
  else:
    if Sum == 0:
      break
    while(K<0):
      i = i - 1
      K = K + A[i]
      Sum = Sum - 1
    Sum += 1
  S.append(Sum)
print(max(S))

Submission status: Runtime Error

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

c=list()

K=0
while k>K:
    
    c.append(min(a))
    a.remove(min(a))
    K += min(a)

    if k>K:
       c.append(min(b))
       b.remove(min(b))
       K += min(b)

print(len(c))

Submission status: Runtime Error

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

A_ = list(itertools.accumulate(A))
B_ = list(itertools.accumulate(B))


l = len(A_)
ans = max(ans, bisect.bisect_right(B_, K))
for idx, i in enumerate(A_):
  if i <= K:
          ans = max(idx+1 + bisect.bisect_right(B_, K-i), ans)
  
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = A + B
output = 0
a = 0
num = 0
if C[0] > K:
    print(0)
else:
    for i in range(N+M):
        num += C[a]
        if num <= K:
            output += 1
            num += C[a+len(A)]
            if num <= K:
                output += 1
                pass
            else:
                print(output)
                break
            a += 1

Submission status: Runtime Error

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

ruiA, ruiB = [0], [0]

for i in range(N):
    ruiA.append(ruiA[i] + A[i])

for j in range(M):
    ruiB.append(ruiB[j] + B[j])

tmpa, tmpb = 0, 0
tmp = 0
t = False
for i in range(N + M + 1):
    if i <= N and ruiA[i] <= K:
        continue
    if i <= M and ruiB[i] <= K:
        continue
    if ruiA[N] + ruiB[i - N] <= K:
        continue
    if ruiA[i - M] + ruiB[M] <= K:
        continue
    
    t = False
    for j in range(max(0, i - N), min(i, M)):
        if ruiA[i - j] + ruiB[j] <= K:
            t = True
            break

    if not t:
        print(i - 1)
        exit()

print(N + M)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a[i]+a_sum[i])
    if a_sum[i]>1e+9:
        break
for i in range(m):
    b_sum.append(b[i]+b_sum[i])
    if b_sum[i]>1e+9:
        break
        
ans = 0
for i in range(len(b_sum)):
    if a_sum[i]>k:
        break
    time = k - a_sum[i]
    for j in range(len(b_sum)):
        if time<b_sum[j+1]:
            break
    if time>=b_sum[len(b_sum)]:
        j = len(b_sum)
    ans = max(ans,i+j)
    
print(ans)