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:
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N,M,K=mis()
    A=lmis()
    B=lmis()
    A.reverse()
    B.reverse()
    c = 0
    t = 0
    s = []
    while A:
        a = A.pop()
        if t + a <= K:
            t += a
            c += 1
            s.append(a)
        else:
            break
    if t < K:
        while B:
            b = B.pop()
            if t + b <= K:
                t += b
                c += 1
            else:
                break
    #
    ans = c
    while s and B:
        t -= s.pop()
        c -= 1
        if t+B[-1]<=K:
            t += B.pop()
            c += 1
        ans = max(ans, c)
    print(ans)









main()

Submission status: Wrong Answer

Solution code:
from collections import deque

N,M,K = map(int,input().split())
AList = list(map(int,input().split()))
BList = list(map(int,input().split()))

AList.append(10**10)
BList.append(10**10)

AList= deque(AList)
BList= deque(BList)

cnt = 0
s = 0

for i in range(2*(N+1)):
  a = AList[0]
  b = BList[0]
  if a <= b and s+a<=K:
    s += a
    AList.popleft()
    cnt += 1
  elif b <= a and s+b<=K:
    s += b
    BList.popleft()
    cnt += 1
    
    
print(int(cnt))

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

Submission status: Wrong Answer

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

ans = 0
while k > 0:
    if len(a) + len(b) == 0:
        break
    if len(a) == 0:
        if b[0] > k:
            break
        k -= b[0]
        ans += 1
        del b[0]
    elif len(b) == 0:
        if a[0] > k:
            break
        k -= a[0]
        ans += 1
        del a[0]
    elif a[0] <= b[0]:
        if a[0] > k:
            break
        k -= a[0]
        ans += 1
        del a[0]
    else:
        if b[0] > k:
            break
        k -= b[0]
        ans += 1
        del b[0]

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()))
ans = 0
A_top = A[0]
B_top = B[0]
A_idx = 1
B_idx = 1
while K:
    if A_top == B_top == float('inf'):
        break
    if A_top > B_top:
        if K < B_top:
            break
        K -= B_top
        ans += 1
        if B_idx < M:
            B_top = B[B_idx]
            B_idx += 1
        else:
            B_top = float('inf')
    else:
        if K < A_top:
            break
        K -= A_top
        if A_idx < N:
            A_top = A[A_idx]
            A_idx += 1
        else:
            A_top = float('inf')
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

total = 0

A_pos = 0
B_pos = 0

if sum(A)+sum(B) <= K:
    print(N+M)
    exit(0)

while True:
    if A_pos >= N:
        total += B[B_pos]
        B_pos += 1
    elif B_pos >= M:
        total += A[A_pos]
        A_pos += 1
    else:
        total += min(A[A_pos], B[B_pos])
        if A[A_pos]<=B[B_pos]:
            A_pos += 1
        else:
            B_pos += 1
    
    if total > K:
        print(A_pos+B_pos-1)
        exit(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
#from numba import njit

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

#@njit

count = 0
t = min(A[0],B[0]) <= K
while (t):
    if (len(B) == 0):
        K -= A[0]
        A = A[1:]
    elif (len(A) == 0):
        K -= B[0]
        B = B[1:]
    elif(A[0] < B[0]):
        K -= A[0]
        A = A[1:]
    else:
        K -= B[0]
        B = B[1:]
    count += 1
    if ((len(A),len(B)) == (0,0)):
        t = False
    elif (len(A) == 0):
        t = B[0] <= K
    else:
        t = A[0] <= K

print(count)

Submission status: Wrong Answer

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

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

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

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

    # empty
    if atop == 10**10 and btop == 10**10:
        break

    if atop < btop:
        if tot + atop <= k:
            tot += a.popleft()
            count += 1
        else:
            break
    elif btop < atop:
        if tot + btop <= k:
            tot += b.popleft()
            count += 1
        else:
            break
    else:
        if tot + atop > k: break
        else:
            rema = True
            for i, j in zip(a, b):
                if i < j:
                    rema = True
                if j < i:
                    rema = False
            if rema:
                tot += a.popleft()
                count += 1
            else:
                tot += b.popleft()
                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
a_index = 0
b_index = 0
ans = 0

while total <= k:

    if a_index >= n and b_index >= m:
        break
    if a_index >= n:
        total += b[b_index]
        b_index += 1
        ans += 1
        continue
    if b_index >= m:
        total += a[a_index]
        a_index += 1
        ans += 1
        continue

    if a[a_index] <= b[b_index]:
        total += a[a_index]
        a_index += 1
    else:
        total += b[b_index]
        b_index += 1
    ans += 1
    if total > k:
        ans -= 1
        break
print(ans)

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()))
ans = 0
a,b = A.popleft(), B.popleft()
ok = True
while k > 0:
    if ok:
        if a <= b and k - a >= 0:
            k -= a
            ans += 1
            if A: a = A.popleft()
            else: ok = False
        elif b < a and k-b >=0:
            k -= b
            ans += 1
            if B: b = B.popleft()
            else: ok = False
        else: break
    else:
        if A:
            if k-a >= 0:
                k -= a
                ans += 1
                if A:a = A.popleft()
            else: break
        else:
            if k-b >= 0:
                k-= b
                ans += 1
                if B:b = B.popleft()
            else: break
print(ans)

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, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, M, K = MAP()
A = deque(LIST())
B = deque(LIST())
A.append(INF)
B.append(INF)

cnt = 0
time = 0
a = 0
b = 0

while time <= K:
	if A[a] < B[b]:
		time += A[a]
		a += 1
	else:
		time += B[b]
		b += 1
	cnt += 1


print(max(cnt-1, 0))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right,bisect_left
from itertools import accumulate

def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A = [0] + list(accumulate(A))
    B = list(accumulate(B))
    # print(A,B)
    ans = 0
    for i in range(N+1):
        if K - A[i] > 0:
            j = bisect_right(B,K-A[i])
            # print(i,j,K-A[i])
            ans = max(ans,i+j)

    print(ans)
        


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

i = 0
j = 0
arr = []
while True:
    if i < n and j < m:
        if A[i] < B[j]:
            arr.append(A[i])
            i += 1
        else:
            arr.append(B[j])
            j += 1
    elif i >= n:
        arr.extend(B[j:])
        break
    else:
        arr.extend(A[i:])
        break

t = 0
i = 0
cnt = 0
while t < k:
    if i < n + m and t + arr[i] <= k:
        t += arr[i]
        i += 1
    else:
        break
print(i)

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()))
cnt=0
time=0
for i in range(len(A)+len(B)):
  if A[0]<=B[0]:
    if time+A[0]<=k:
      cnt+=1
      time+=A[0]
      del A[0]
      if len(A)==0:
        A.append(0)
    else:
      break;
  elif A[0]>B[0]:
    if time+B[0]<=k:
      cnt+=1
      time+=B[0]
      del B[0]
      if len(B)==0:
        B.append(0)
    else:
      break;

print(cnt)

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

cnt = 0
cost = 0

while k >= cost:
    if not a and not b:
        break
    elif not a:
        tmp = b.pop(0)
        if cost + tmp <= k:
            cnt += 1
            cost += tmp
        else:
            break
    elif not b:
        tmp = a.pop(0)
        if cost + tmp <= k:
            cnt += 1
            cost += tmp
        else:
            break
    else:
        if a[0] > b[0]:
            tmp = b.pop(0)
            if cost + tmp <= k:
                cnt += 1
                cost += tmp
            else:
                break
        else:
            tmp = a.pop(0)
            if cost + tmp <= k:
                cnt += 1
                cost += tmp
            else:
                break

print(cnt)

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
x=0
while ans<=k:
    if a and b:
        if a[0]<=b[0]:
            z=a[0]
            ans+=z
            del a[0]
        else:
            z=b[0]
            ans+=z
            del b[0]
    else:
        if a:
            ans+=a[0]
            del a[0]
        elif b:
            ans+=b[0]
            del b[0]
        else:
            break
    if ans>k:
        break
    x+=1
    #print(ans)
print(x)

Submission status: Wrong Answer

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

a, b = 0, 0
time = 0
ans = 0
while time <= K:
    if a < len(A) and b < len(B):
        if A[a] < B[b] and time +A[a] <= K:
            ans += 1
            time += A[a]
            a += 1
        elif A[a] > B[b] and time +B[b] <= K:
            ans += 1
            time += B[b]
            b += 1
        else:
            break
    elif a >= len(A) and b < len(B):
        if time +B[b] <= K:
            ans += 1
            time += B[b]
            b += 1
        else:
            break
    elif a < len(A) and b >= len(B):
        if time +A[a] <= K:
            ans += 1
            time += A[a]
            a += 1
        else:
            break
    else:
        break
print(ans)

Submission status: Wrong Answer

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

from itertools import accumulate
a = list(accumulate(a))
b = list(accumulate(b))

from collections import deque
u = deque([0])
a.append(0)

import bisect
for i in range(n+1):
    if k-a[i]>=0:
        index = bisect.bisect_left(b,k-a[i])
        u.append(index+i)
    else:
        break
print(max(u))

Submission status: Wrong Answer

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

ans = 0
m = 0
for i in A:
  m += i
  if m > K:
    break
  ans += 1

C = [0] * N
C[0] = A[0]
for i in range(1, N):
  C[i] = C[i - 1] + A[i]

D = [0] * M
D[0] = B[0]
for i in range(1, M):
  D[i] = D[i - 1] + B[i]

if ans == 0:
  t = 0
else:
  t = C[ans - 1]

k = ans
n = ans
for i in range(M):
  m = D[i]
  if m > K: break
  while m + t > K:
    n -= 1
    if n >= -1:
      t = 0
      break
    t = C[n - 1]
  ans = max(ans, i + 1 + n)

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()))
count=0
s=0
while(s<k):
    if not a and not b:
        break
    elif not a:
        s+=b.pop(0)
    elif not b:
        s+=a.pop(0)
    else:
        s+=min(a,b).pop(0)
    if s<=k:
        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()))
ans = 0
while k>0:
    if len(a)==0 and len(b)==0:
        break
    elif len(a)==0:
        k-=b[0]
        b.pop(0)
    elif len(b)==0:
        k-=a[0]
        a.pop(0)
    elif a[0]>b[0]:
        k-=b[0]
        b.pop(0)
    else:
        k-=a[0]
        a.pop(0)
    if k>=0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

time = 0
a_i = 0
b_i = 0
while time <= k:
    if a_i >= n:
        cur_a = math.inf
    else:
        cur_a = alist[a_i]

    if b_i >= m:
        cur_b = math.inf
    else: 
        cur_b = blist[b_i]

    if cur_a == math.inf and cur_b == math.inf:
        break

    if cur_a < cur_b:
        time += alist[a_i]
        a_i += 1
    else:
        time += blist[b_i]
        b_i += 1

if time <= k:
    print(a_i+b_i)
else:
    print(a_i+b_i-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.reverse()
B.reverse()

ans = 0
total_time = 0
while A or B:
    if not A:
        t = B.pop()
    elif not B:
        t = A.pop()
    else:
        if A[-1] < B[-1]:
            t = A.pop()
        else:
            t = B.pop()
    total_time += t
    if total_time <= K:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

for i in range(n+m):  
  if a == [] and b == []:
    break
  elif a == []:
    time = b[0]
    b.pop(0)
  elif b == []:
    time = a[0]
    a.pop(0)
  elif a[0] > b[0]:
    time = b[0]
    b.pop(0)
  else:
    time = a[0]
    a.pop(0)
  total_time += time
  if total_time > k:
    break
  num += 1 
  
print(num)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import accumulate
N,M,K= map(int,input().split())

inf = 10**10
A = [inf] + list(map(int,input().split()))[::-1]
B = [inf] + list(map(int,input().split()))[::-1]

ma = A.pop()
mb = B.pop()

t = 0
ans = 0
while True:
    if len(A) == 0 and len(B) == 0:
        break
    if ma <= mb:
        t += ma
        ma = A.pop()
    else:
        t += mb
        mb = B.pop()

    if t <= K:
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

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

A.append(10**10)
B.append(10**10)

cnt_a = 0
cnt_b = 0
time = 0
ans = 0

while time <= k:
    if cnt_a ==n and cnt_b==m:
        break
    if A[cnt_a] < B[cnt_b] and time+A[cnt_a]<=k:
        time += A[cnt_a]
        cnt_a += 1
        ans += 1
    elif A[cnt_a] >= B[cnt_b] and time+B[cnt_b]<=k:
        time += B[cnt_b]
        cnt_b += 1
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

for i in range(1, len(A)) :
  A[i] += A[i - 1]
for i in range(1, len(B)) :
  B[i] += B[i - 1]

ret = 0
a = len(A) - 1
b = 0
while b < len(B) :
  while a >= 0 and A[a] + B[b] > K :
    a -= 1
  if a >= 0 :
    ret = max(ret, a + b + 2)
  b += 1
  
print(ret)

Submission status: Wrong Answer

Solution code:
acount = 0
bcount = 0

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

curr_time = 0
books = 0
a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))

while curr_time < limit:
  if acount < a:
    if bcount < b:
      if a_books[acount] < b_books[bcount]:
        curr_time += a_books[acount]
        acount += 1
        books += 1
      else:
        curr_time += b_books[acount]
        bcount += 1
        books += 1
    else: 
      curr_time += a_books[acount]
      acount += 1
      books += 1
  else:
    curr_time += b_books[acount]
    bcount += 1
    books += 1
    
print(books)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

A, B

INF = 1 << 30
A = [INF] + A[::-1]
B = [INF] + B[::-1]

n = 0
while True:
    if A[-1] > B[-1]:
        A, B = B, A
    x = A.pop()
    if K >= x:
        n += 1
        K -= x
    else:
        break

print(n)

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()))
t = 0
num = 0
an = 0
bn = 0
while (an < len(a)) & (bn < len(b)):
    if a[an] <= b[bn]:
        t += a[an]
        if t > k:
            break
        num += 1
        an += 1
    else:
        t += b[bn]
        if t > k:
            break
        num += 1
        bn += 1

if t < k:
    if an == len(a):
        while (bn < len(b)):
            t += b[bn]
            if t > k:
                break
            num += 1
            bn += 1
    elif bn == len(b):
        while (an < len(a)):
            t += a[an]
            if t > k:
                break
            num += 1
            an += 1

print(num)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = 0
f = 0
while(True):
    if(a and b and a[0] > b[0]):
        c += b.pop(0)
        if(c > k):
            break
    elif(a and b and a[0] <= b[0]):
        c += a.pop(0)
        if(c > k):
            break
    elif(a and not b):
        c += a.pop(0)
        if(c > k):
            break
    elif(b and not a):
        c += b.pop(0)
        if(c > k):
            break
    elif(not a and not b):
        break
    
    f += 1    
print(f)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
A = [a for a in map(int,input().split())]
B = [b for b in map(int,input().split())]

ans = 0

while True:
    if K < 0:
        ans -= 1
        break
    elif K == 0:
        break
    elif len(A)==0 and len(B)==0:
        break
    if len(B)==0:
        K -= A[0]
        A.pop(0)
        ans += 1
    elif len(A)==0:
        K -= B[0]
        B.pop(0)
        ans += 1
    elif A[0] <= B[0]:
        K -= A[0]
        A.pop(0)
        ans += 1
    elif A[0] > B[0]:
        K -= B[0]
        B.pop(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 = k
cnt = 0
while time > 0:
    if not b:
        read = a.pop(0)
        time -= read
        cnt += 1
        #print(a, b, time)
    elif not a:
        read = b.pop(0)
        time -= read
        cnt += 1
        #print(a, b, time)
    elif a[0] <= b[0]:
        read = a.pop(0)
        time -= read
        cnt += 1
        #print(a, b, time)
    elif a[0] > b[0]:
        read = b.pop(0)
        time -= read
        cnt += 1
        #print(a, b, time)
if time < 0:
    print(cnt - 1)
else:
    print(cnt)

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=A+B
C.sort()
if C[0]>K:
  print('0')
  exit()
k=0
ans=0
for i in range(len(C)):
  k+=C[i]
  ans+=1
  if k>=K:
    break
if k==K:
  print(ans)
else:
  print(ans-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()))

count = 0
for i in range(N + M):
  if len(A) == 0:
    book = B[0]
    B = B[1:]
  elif len(B) == 0:
    book = A[0]
    A = A[1:]
  else:
    if A[0] <= B[0]:
      book = A[0]
      A = A[1:]
    else:
      book = B[0]
      B = B[1:]
  
  count += 1
  K -= book
  if K < 0:
    count -= 1
    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()))

sumtime = 0

bi = 0
while bi < m and sumtime + b[bi]<=k:
    sumtime += b[bi]
    bi += 1
    
ans = bi
for ai in range(n):
    sumtime += a[ai]
    while bi>=1 and sumtime>k:
        sumtime -= b[bi-1]
        bi -= 1
    
    if sumtime<=k:
        ans = max(ans, ai+bi+1)
    
    if bi<=0: break
    
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n, m, k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
bc = [0]*(m+1)
for i in range(m):
    bc[i+1] = bc[i] + b[i]
bc = bc[1:]

ans = bisect.bisect_right(bc, k) # 0冊
totala = 0
na = 0
for i in range(n):
    totala += a[i]
    if totala >= k:
        break
    na += 1
    ba = bisect.bisect_right(bc, k-totala)
    ans = max(ans, na+ba)
print(ans)

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 = deque(A)
b = deque(B)

ans = 0
time = 0

while True:
    if time >= K:
        break
    if len(a) == 0 and len(b) == 0:
        break

    if len(a) == 0:
        if b[0] > K - time:
            break
        time += b[0]
        b.popleft()
    elif len(b) == 0:
        if a[0] > K - time:
            break
        time += a[0]
        a.popleft()
    elif a[0] < b[0]:
        if a[0] > K - time:
            if b[0] > K - time:
                break
            else:
                time += b[0]
                b.popleft()
        else:
            time += a[0]
            a.popleft()
    else:
        if b[0] > K - time:
            if a[0] > K - time:
                break
            else:
                time += a[0]
                a.popleft()
        else:
            time += b[0]
            b.popleft()
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:

import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(float("INF"))
b.append(float("INF"))
la = [a[0]]
lb = [b[0]]
for i in range(1,n):
    la.append(la[-1]+a[i])
for i in range(1,m):
    lb.append(lb[-1]+b[i])
ans = 0
for i in range(n):
    if la[i] > k:
        break
    x = k-la[i]

    count = i+1
    ind = bisect.bisect_right(lb,x)
    count += ind
    ans = max(ans,count)
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()))
s=0
n=0
while len(a)>0 or len(b)>0:
    if len(a)==0:
        c=b.pop(0)
    elif len(b)==0:
        c=a.pop(0)
    else:
        c=a.pop(0) if a[0]<=b[0] else b.pop(0)
        if s+c>k:
            break
    s+=c
    n+=1
print(n)

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

X= sorted(A+B)
L = len(X)
ans = 0
S = 0
while S <= K:
  if ans == L:
    ans += 1
    break
  S += X[ans]
  ans += 1
  
print(ans-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect


n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
A.insert(0, 0)
B.insert(0, 0)

for i in range(1, len(A)):
    A[i] = A[i - 1] + A[i]

for i in range(1, len(B)):
    B[i] = B[i - 1] + B[i]


res = 0
for i in range(n):
    if k < A[i]:
        break

    j = bisect.bisect_left(B, k - A[i])
    if j < len(B) and B[j] > k - A[i]:
        j -= 1


    cnt = i + j
    res = max(res, cnt)
print(res)

Submission status: Wrong Answer

Solution code:
inf = 10**9
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.append(inf)
b.append(inf)
cur_a = 0
cur_b = 0
total = 0
count = 0
while a[cur_a] != inf or b[cur_b] != inf:
    total += min(a[cur_a], b[cur_b])
    if total > k:
        break
    count += 1
    if a[cur_a] > b[cur_b]:
        cur_b += 1
    else:
        cur_a += 1
print(count)