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 collections import deque

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

A_que = deque()
for i in range(N):
    A_que.append(A[i])
    
B_que = deque()
for i in range(M):
    B_que.append(B[i])

time = 0
count = 0
while True:
    if len(A_que) == 0 and len(B_que) == 0:
        break
    
    book_A = None
    book_B = None
    if len(A_que) == 0:
        book = B_que.popleft()
    elif len(B_que) == 0:
        book = A_que.popleft()
    else:
        book_A = A_que.popleft()
        book_B = B_que.popleft()
        if book_A < book_B:
            book = book_A
        else:
            book = book_B
    if time + book <= K:
        time += book
        count += 1
        if book_A == None:
            pass
        elif book_B == None:
            pass
        else:
            if book_A < book_B:
                B_que.appendleft(book_B)
            else:
                A_que.appendleft(book_A)
    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()))
ans = 0
for i in range(1000000):
    if len(a) == 0:
        if k - b[0] > 0:
            ans += 1
            k -= b.pop(0)
        elif k - b[0] == 0:
            print(ans + 1)
            exit()
        else:
            print(ans)
            exit()
    elif len(b) == 0 :
        if k - a[0] > 0:
            ans += 1
            k -= a.pop(0)
        elif k - a[0] == 0:
            print(ans + 1)
            exit()
        else:
            print(ans)
            exit()
    elif len(a) == 0 and b == 0:
        print(ans)

    elif a[0] >= b[0]:
        if k - b[0] > 0:
            ans += 1
            k -= b.pop(0)
        elif k - b[0] == 0:
            print(ans + 1)
            exit()
        else:
            print(ans)
            exit()
    elif a[0] < b[0]:
        if k - a[0] > 0:
            ans += 1
            k -= a.pop(0)
        elif k - a[0] == 0:
            print(ans + 1)
            exit()
        else:
            print(ans)
            exit()

Submission status: Wrong Answer

Solution code:
N, M, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
t = 0
ans = 0
while True:
    if len(A)!=0 and len(B)!=0:
        b = min(A[0], B[0])
        if A[0] == b:
            t += A.pop(0)
        else:
            t += B.pop(0)
    elif len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        t += B.pop(0)
    else:
        t += A.pop(0)
    if t > K:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().strip().split())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
i=j=0

time=0
while j<m:
    time+=B[j]
    if time >k:
        time-=B[j]
        break
    j += 1
j-=1
rem=k-time
ans=j+1
cnt=ans
while j>=0:
    while i<n and rem-A[i]>=0:
        rem-=A[i]
        i+=1
        cnt+=1
    ans=max(ans,cnt)
    
    rem+=B[j]
    j-=1
    cnt-=1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    #n = int(stdin.readline().rstrip())
    n,m,k = map(int, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))
    B = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = 0
    time = 0
    a = 0
    b = 0
    while a < n and b < m:
        if A[a] < B[b]:
            if time + A[a] <= k:
                ans += 1
                time += A[a]
                a += 1
            else:
                print(ans)
                exit()
        else:
            if time + B[b] <= k:
                ans += 1
                time += B[b]
                b += 1
            else:
                print(ans)
                exit()
    if a == n:
        #B
        while b < m:
            if time + B[b] <= k:
                ans += 1
                time += B[b]
                b += 1
            else:
                print(ans)
                exit()
        print(ans)
        exit()
    else:
        #A
        while a < m:
            if time + A[a] <= k:
                ans += 1
                time += A[a]
                a += 1
            else:
                print(ans)
                exit()
        print(ans)
        exit()



if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time = 0
count = 0
for _ in range(n+m):
    if len(a)==0 or len(b)==0:
        if len(a)==0:
            time +=b[0]
            if time >k:
                break
            del b[0]
            count+=1
        elif len(b)==0:
            time +=a[0]
            if time >k:
                break
            del a[0]
            count+=1
    else:
        if a[0]<b[0]:
            time += a[0]
            if time >k:
                break
            del a[0]
            count+=1
        else:
            time += b[0]
            if time >k:
                break
            del b[0]
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
list = []
tmp = 0
count = 0
while len(A) != 0 and len(B) != 0:
  if A[0] < B[0]:
    list.append(A.pop(0))
  else:
    list.append(B.pop(0))
  if len(A) == 0:
    list.extend(B)
  elif len(B) == 0:
    list.extend(A)
while len(list) != 0:
  tmp += list.pop(0)
  if tmp > K:
    break
  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()))
a=a[::-1]
b=b[::-1]
n1=len(a)-1
n2=len(b)-1
c=0
while(n1!=-1 and n2!=-1 and a[n1]<=k and b[n2]<=k):
    if a[n1]<=b[n2]:
        k-=a.pop()
        n1-=1
    else:
        k-=b.pop()
        n2-=1
    c+=1

if(n1!=-1):
    while(n1!=-1 and a[n1]<=k):
        k-=a.pop()
        n1-=1
        c+=1
if(n2!=-1):
    while(n2!=-1 and b[n2]<=k):
        k-=b.pop()
        n2-=1
        c+=1
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a_c = 0
b_c = 0
while K>0:
    if len(A) > a_c and len(B) > b_c:
        if A[a_c] < B[b_c]:
            K = K-A[a_c]
            a_c+=1
        else:
            K = K-B[b_c]
            b_c+=1
    elif len(A) <= a_c and len(B) > b_c:
        K = K-B[b_c]
        b_c+=1
    elif len(A) > a_c and len(B) <= b_c:
        K = K-A[a_c]
        a_c+=1
    else:
        break
    
if K>=0:
    print(a_c + b_c)
else:
    print(a_c + b_c - 1)

Submission status: Wrong Answer

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

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

a_counter = 0
a_all_flag = -1
b_counter = 0
b_all_flag = -1
total_time = 0
total_book = 0

for cnt in range(n+m):
    if a[a_counter] <= b[b_counter] and a_all_flag != 1:
        if k - a[a_counter] >= 0:
            k -= a[a_counter]
            if a_counter+1 < n:
                a_counter += 1
            else:
                a_all_flag = 1
            total_book += 1
        else:
            break
    elif a[a_counter] > b[b_counter] and b_all_flag != 1:
        if k - b[b_counter] >= 0:
            k -= b[b_counter]
            if b_counter+1 < m:
                b_counter += 1
            else:
                b_all_flag = 1
            total_book += 1
        else:
            break
    elif a_all_flag != 1 and b_all_flag == 1:
        if k - a[a_counter] >= 0:
            k -= a[a_counter]
            if a_counter+1 < n:
                a_counter += 1
            else:
                a_all_flag = 1
            total_book += 1
        else:
            break
    elif a_all_flag == 1 and b_all_flag != 1:
        if k - b[b_counter] >= 0:
            k -= b[b_counter]
            if b_counter+1 < m:
                b_counter += 1
            else:
                b_all_flag = 1
            total_book += 1
        else:
            break

print(total_book)

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()))
f=float('inf')
a.append(f)
b.append(f)
at,bt=0,0
p=0
while p<=k:
    if a[at]<=b[bt]:
        p+=a[at]
        at+=1
    else:
        p+=b[bt]
        bt+=1
    '''
    if n==at and m==bt:
        print(at+bt)
        break
    #print(p)
    '''
print(at+bt-1)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def X(): return list(input())
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0


X,Y,Z = I()
A = l()
B = l()
sum = 0
i = 0
j = 0

while sum <= Z:
    if len(A) + len(B) == 0:
        print(X+Y)
        sys.exit()
    if len(A) == 0:
        a = 10000000000000
    else:
        a = A[0]
    if len(B) == 0:
        b = 10000000000000
    else:
        b = B[0]
    if a >= b:
        sum += b
        B.pop(0)
        count += 1
    elif a < b:
        sum += a
        A.pop(0)
        count += 1

print(count-1)

Submission status: Wrong Answer

Solution code:
import sys
import math 
from collections import deque

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

i=0
j=0
ans=0
tmp=0
re=0
while True:
    if i==n and j==m:

        print(ans)
        sys.exit()
    elif i==n:
        re=b[j]
        j+=1
    elif j==m:
        re=A[i]
        i+=1
    else:
        q=A[i]
        u=b[j]
        re=min(q,u)
        if re ==q:
            i+=1
        else:
            j+=1

    tmp+=re
    if tmp > k:
        print(ans)
        sys.exit()
    ans+=1

Submission status: Wrong Answer

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
sum = 0
acount = 0
bcount = 0

while(sum < k):
    if acount == len(a) and bcount == len(b):
        break

    elif acount == len(a):
        mi = b[bcount]
        sum += mi
        ans += 1
        bcount += 1

    elif bcount == len(b):
        mi = a[acount]
        sum += mi
        ans += 1
        acount += 1

    else:
        mi = min(a[acount], b[bcount])
        sum += mi
        ans += 1
        if mi == a[acount]:
            acount += 1
        else:
            bcount += 1

if k < sum:
    print(ans - 1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = input().split(" ")
n = int(n)
m = int(m)
k = int(k)

a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]

read = 0
cnt = 0
ai = 0
bi = 0

def peep(books, current_index, current_capacity):
	scanned = 0
	cnt = 0
	while current_capacity > scanned:
		scanned = books[current_index]
		current_index+=1
		if current_index >= len(books):
			break
		cnt +=1
	if scanned > current_capacity:
		cnt -= 1
	return cnt

while read < k:
	if ai >= n and bi >= m:
		break
	elif ai >= n:
		read += b[bi]
		cnt += 1
		bi+= 1
	elif bi >= m:
		read += a[ai]
		cnt += 1
		ai += 1
	elif peep(a, ai, k - read) < peep(b, bi, k - read):
		read += a[ai]
		cnt += 1
		ai += 1
	else:
		read += b[bi]
		cnt += 1
		bi += 1
	if read > k:
		cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=0
b=0
ans=0
for _ in range(N+M):
  if a<N and b<M:
    if A[a]<B[b]:
      K-=A[a]
      a+=1
    elif A[a]>B[b]:
      K-=B[b]
      b+=1
    elif A[a]==B[b]:
      for i in range(1,N+M):
        if a<N-i-1 and b<M-i-1:
          if A[a+i]<B[b+i]:
            K-=A[a]
            a+=1
            break
          elif A[a+i]>B[b+i]:
            K-=B[b]
            b+=1
            break
        elif a<N-i-1 and b>=M-i-1:
          if A[a+i]<B[-1]:
            K-=A[a]
            a+=1
            break
          elif A[a+i]>B[-1]:
            K-=B[b]
            b+=1
            break
        elif b<M-i-1 and a>=N-i-1:
          if B[b+i]<A[-1]:
            K-=B[b]
            b+=1
            break
          elif B[b+i]>A[-1]:
            K-=A[a]
            a+=1
            break
        elif a>=N-i-1 and b>=M-i-1:
          K-=A[a]
          a+=1
          break
  elif a<N:
    K-=A[a]
    a+=1
  elif b<M:
    K-=B[b]
    b+=1
  else:
    break
  if K>=0:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
count = 0
Anum = 0
Bnum = 0
judgea = 0
judgeb = 0
while time<=K:
    if judgea == 2 and judgeb ==1:
        break
    
    if A[Anum]>=B[Bnum] or judgea == 2:
        time += B[Bnum]
        
        if Bnum+1 >= len(B):
            judgeb = 1
        else:
            Bnum += 1
        count += 1
    elif A[Anum]<=B[Bnum] or judgeb == 1:
        time += A[Anum]
       
        if Anum+1 >= len(A):
            judgea = 2
        else:
            Anum += 1
        count += 1
if time>K:
    count-= 1

print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))[::-1]
b=list(map(int,input().split()))[::-1]
for i in range(n+m):
    if len(a)!=0 and len(b)!=0:
        if a[-1]==b[-1]:
            c=a[-1]
            f=0
        else:
            c=min(a[-1],b[-1])
            f=1 if c==b[-1] else 0
    elif len(a)!=0:
        c=a[-1]
        f=0
    elif len(b)!=0:
        c=b[-1]
        f=1
    else:
        break
    if k-c<0:
        print(i)
        exit()
    else:
        k-=c
        b.pop() if f else a.pop()
print(n+m)

Submission status: Wrong Answer

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

class queue:
    def __init__(self):
        self.listQ = []
    def pop(self):
        r = self.listQ[0]
        del self.listQ[0]
        return r
    def push(self, val):
        self.listQ.append(val)
    def length(self):
        return len(self.listQ)
    def peek(self):
        return self.listQ[0]
    def print(self):
        print(self.listQ)

qA = queue()
qB = queue()
for a in listA:
    qA.push(a)
for b in listB:
    qB.push(b)
timer = 0
count = 0
while True:
    if qA.length() and qB.length():
        bA = qA.peek()
        bB = qB.peek()
        if bA <= bB:
            if timer+bA <= k:
                qA.pop()
                count+=1
                timer+=bA
            else:
                break
        else:
            if timer+bB <= k:
                qB.pop()
                count += 1
                timer += bB
            else:
                break
    elif qA.length():
        bA = qA.peek()
        if timer+bA <= k:
            qA.pop()
            count += 1
            timer += bA
        else:
            break
    elif qB.length():
        bB = qB.peek()
        if timer+bB <= k:
            qB.pop()
            count += 1
            timer += bB
        else:
            break
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
# import sys
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split())) + [10**13]
B = [0] + list(map(int, input().split())) + [10**13]
sum_t = 0
cumsumA = [0]
cumsumB = [0]
ansA = N
ansB = M
tmp = 0
for i in range(1, N+1):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = 0
for i in range(1, M+1):
    tmp = tmp + B[i]
    if tmp > K:
        ansB = i-1
        break
    cumsumB += [tmp]

ans_t = cumsumA[ansA] + cumsumB[ansB]
ansAA = ansA
ansBB = ansB
ans = ansA + ansB
while K < ans_t:
    ai, bi = A[ansA], B[ansB]
    if ai >= bi:
        ans_t -= ai
        ans -= 1
        ansA -= 1
        bi = B[ansB+1]
        while bi + ans_t <= K:
            ans += 1
            ans_t += bi
            ansB += 1
            bi = B[ansB+1]
    else:
        ans_t -= bi
        ans -= 1
        ansB -= 1
        ai = A[ansA+1]
        while ai + ans_t <= K:
            ans += 1
            ans_t += ai
            ansA += 1
            ai = A[ansA+1]

print(max([ans, ansAA, ansBB]))
# print(ansA, ansB)

Submission status: Wrong Answer

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

a[:] = map(int, input().split())
b[:] = map(int, input().split())
b.insert(0, 0)
book_num = 0
for i in range(n+1):
    read_time = 0
    read_time = sum(a[:i])
    # print(read_time)
    for j in range(m+1):
        read_time += b[j]
        # print("a" + str(read_time))
        if read_time < k:
            continue
        if read_time == k:
            # print("a")
            book_num = i + j
        if (i + j - 3) > book_num:
            book_num = i + j - 3
            break

print(book_num)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int,input().split())
    from collections import deque
    from heapq import heappush, heappop
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ad = deque(a)
    bd = deque(b)
    cnt = 0
    inf = 10**18
    p = inf
    q = inf
    for i in range(m+n):
        if p == inf and ad:
            p = ad.popleft()
        if q == inf and bd:
            q = bd.popleft()
        if p == q:
            print('')
        if p < q:
            n -= 1
            k -= p
            p = inf
        else:
            m -= 1
            k -= q
            q = inf
        if k >= 0:
            cnt += 1
        if k <= 0:
            break
    print(cnt)              


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m,k=mp()
A=lmp()
B=lmp()
a=[A[0]]
b=[B[0]]
for i in range(1,n):
    a.append(a[i-1]+A[i])
for i in range(1,m):
    b.append(b[i-1]+B[i])
a.insert(0,0)
b.insert(0,0)
a.append(float("inf"))
b.append(float("inf"))
ans=0

ind=bisect.bisect_left(a,k)
j=0
ans=ind-1
for i in range(ind-1,0,-1):
    while a[i]+b[j]>k or a[i]+b[j+1]<=k:
        j+=1

    ans=max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
time = 0
count = 0
while time < K:
    if len(A) > 0 and len(B) > 0:
        if A[0] < B[0]:
            time += A.pop(0)
            count += 1
        else:
            time += B.pop(0)
            count += 1
    elif len(A) > 0:
        time += A.pop(0)
        count += 1
    elif len(B) > 0:
        time += B.pop(0)
        count += 1
    else:
        break

if time <= K:
    print(count)
else:
    print(count -1)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))

cnt = 0
if A[0] < B[0] and A[0] <= k:
  cnt += 1
  k -= A[0]

for a in A[1:]:
    for b in B:
        if b > a:
          k -= a
          if k > 0: cnt += 1
          break
          
        else:
          k -= b
          if k > 0: cnt += 1
    
print(cnt)

Submission status: Wrong Answer

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

INF = 10 ** 10

al = len(ai)
bl = len(bi)
ax = 0
bx = 0

books   = 0
minutes = 0

while True:
    if ax == al and bx == bl: break

    ca = INF if ax == al else ai[ax]
    cb = INF if bx == bl else bi[bx]

    if ca <= cb:
        c = ca
        ax += 1

    else:
        c = cb
        bx += 1

    # print(minutes, c, ax, bx)

    if minutes + c > k: break

    minutes += c
    books   += 1

print(books)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m, k = [int(e) for e in input().split()]
a = np.array([int(e) for e in input().split()])
b = np.array([int(e) for e in input().split()])

asum = a.cumsum()
bsum = b.cumsum()

#aのみbのみ
onlya = (asum < k).sum()
onlyb = (bsum < k).sum()
ans = max(onlya,onlyb)

asum = asum[:onlya]
asum = bsum[:onlyb]

for i,t in enumerate(asum):
    for j,s in enumerate(bsum):
        if t+s <= k and i+j+2 > ans:
            ans = i+j+2

print(ans)

Submission status: Wrong Answer

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

# N = [3 ,4, 0]
# A = [60, 90, 120]
# B = [80, 150, 80, 150]

M = N[1]
K = N[2]
N = N[0]

s = 0
c1 = 0
c2 = 0

s1 = [A[0]]
s2 = [B[0]]
for i in range(N-1):
    s1.append(s1[i]+A[i+1])
for i in range(M-1):
    s2.append(s2[i]+B[i+1])

C = [0]
for i in range(N):
    if s1[i] > K:
        break    
    k = 0
    while s2[k] <= K-s1[i]:
        k += 1
        if k == M:
            break
    C.append(k+i+1)

print(max(C))

Submission status: Wrong Answer

Solution code:
from collections import deque
from sys import stdin
input = stdin.readline


def main():
  N, M, K = list(map(int, input().split()))
  A = deque(list(map(int, input().split())))
  B = deque(list(map(int, input().split())))
  A.append(float('inf'))
  B.append(float('inf'))

  num_book = 0
  ac_A = [0]*(len(A)+1)
  for i, a in enumerate(A):
    ac_A[i+1] = ac_A[i] + a

  ac_B = [0]*(len(B)+1)
  for i, b in enumerate(B):
    ac_B[i+1] = ac_B[i] + b

  ai = 0
  bi = 0
  while (ai < len(A) or bi < len(B)):
    if (ac_A[ai+1] < ac_B[bi+1]):
      ai += 1
    else:
      bi += 1

    if K >= ac_A[ai] + ac_B[bi]:
      num_book += 1
    else:
      break

  print(num_book)


if(__name__ == '__main__'):
  main()

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 = []

        key = False
        sum_A.append(A[0])
        for i in range(N):
                if i!=0 and key == False:
                        A[i]+=A[i-1]
                        if A[i]>K:
                                key = True
                        sum_A.append(A[i])

        key = False
        sum_B.append(B[0])
        for i in range(M):
                if i!=0 and key==False:
                        B[i]+=B[i-1]
                        if B[i]>K:
                                key = True
                        sum_B.append(B[i])

        #print(A)
        #print(sum_A)
        #print(B)
        #print(sum_B)

        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:
                                print(i,j)
                                max_ij = max(max_ij,i+j+2)
        ans = max_ij

        return ans

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

Submission status: Wrong Answer

Solution code:

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

time = 0
count = 0

while time <= K:
    count += 1
    if len(A) <= 0 and len(B) <= 0:
        break
    a = 1000000001
    b = 1000000001
    if len(A) > 0:
        a = A.pop()
    if len(B) > 0:
        b = B.pop()

    if a < b:
        if b != 1000000001:
            B.append(b)
        time += a
    else:
        if A != 1000000001:
            A.append(a)
        time += b

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.append(0)
B.append(0)
run_time = K
count_A = 0
count_B = 0
#print(N, M ,K)
while(run_time > 0 or count_A + count_B >= N + M):
#	print(count_B , M)
	if(A[count_A] >= B[count_B] and run_time >= A[count_A] and count_A < N):
#		print(N)
		run_time -= A[count_A]
		count_A += 1
#		print(count_A, N)
	elif(A[count_A] < B[count_B] and run_time >= B[count_B] and count_B < M):
		
		run_time -= B[count_B]
		count_B += 1
	else:
		break
print(count_A + count_B)

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

while k>0:

    if not a:
        if not b:
            break

        else:
            k-=b.pop(0)

    else:
        if not b:
            k-=a.pop(0)

        else:        
            if a[0]<=b[0]:
                k-=a.pop(0)

            elif a[0]>b[0]:
                k-=b.pop(0)

    if k>=0:
        ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect as bc

N,M,K = map(int,input().split())
A = [0]*(N+1)
B = [0]*(M+1)
A[1:] = list(map(int,input().split()))
B[1:] = list(map(int,input().split()))
A.append(10**9+10)
B.append(10**9+10)

A_S = [0]*(N+2)
B_S = [0]*(M+2)

for i in range(1,N+2):
    A_S[i] = A_S[i-1]+A[i]
for i in range(1,M+2):
    B_S[i] = B_S[i-1]+B[i]

ans = 0
for i in range(N+2):
    tmp_K = K-A_S[i]
    if tmp_K > 0:
        j = bc.bisect_right(B_S,tmp_K) - 1
        ans = max(i+j,ans)
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())))

count = 0
ans = 0
la = len(a)
lb = len(b)
l = la + lb
ac = 0
bc = 0

if k >= sum(a) + sum(b):
    print(len(a) + len(b))
else:
    while k >= count and l >= ans:
        if la > ac and lb > bc:
            if k >= count + min(a[0], b[0]):
                count += min(a[0], b[0])
                ans += 1
                if b[0] >= a[0]:
                    a.popleft()
                    ac += 1
                else:
                    b.popleft()
                    bc += 1
            else:
                break
        elif la == ac and lb > bc:
            if k >= count + b[0]:
                count += b[0]
                ans += 1
                b.popleft()
                bc += 1
            else:
                break
        elif lb == bc and la > ac:
            if k >= count + a[0]:
                count += a[0]
                ans += 1
                a.popleft()
                ac += 1
            else:
                break
        else:
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque

n,m,k=nii()
a=lnii()
a=deque(a)
b=lnii()
b=deque(b)

t=0
ans=0

while t<=k:
  if a:
    a_c=a.popleft()
  else:
    a_c=10**18
  if b:
    b_c=b.popleft()
  else:
    b_c=10**18

  if a_c<=b_c:
    ans+=1
    t+=a_c
    b.appendleft(b_c)
  else:
    ans+=1
    t+=b_c
    a.appendleft(a_c)

if ans==0:
  print(0)
else:
  print(ans-1)