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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, K, *AB = map(int, read().split())
    A = AB[:N]
    B = AB[N:]

    A = A[::-1]
    B = B[::-1]

    ans = 0
    time = 0
    while time < K:
        if not A and not B:
            break
        if not A:
            if time + B[-1] <= K:
                time += B.pop()
            else:
                break
        elif not B:
            if time + A[-1] <= K:
                time += A.pop()
            else:
                break
        else:
            if A[-1] < B[-1]:
                if time + A[-1] <= K:
                    time += A.pop()
                else:
                    break
            else:
                if time + B[-1] <= K:
                    time += B.pop()
                else:
                    break

    print(N + M - (len(A) + len(B)))
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int, input().split())
*a,=map(int, input().split())
*b,=map(int, input().split())
now=0
cnt=0
from collections import deque  
a=deque(a)
b=deque(b)

while (a or b):
    if a:
        la=a.popleft()
    else:
        la=float('inf')
    if b:
        lb=b.popleft()
    else:
        lb=float('inf')
    if la>=lb:
        if la!=float('inf'):
            a.appendleft(la)
        k-=lb
        if k>=0:
            cnt+=1
        else:
            break
    else:
        if lb!=float('inf'):
            b.appendleft(lb)
        k-=la
        if k>=0:
            cnt+=1
        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()))

# print()
a_i=0
b_i=0
cnt=0
ans=0
while cnt<=k:
    if a_i==len(a) and b_i==len(b):
        ans+=1
        break
    elif b_i==len(b):
        cnt+=a[a_i]
        a_i+=1
        ans+=1
    elif a_i==len(a):
        cnt+=b[b_i]
        b_i+=1
        ans+=1
    elif a[a_i]>=b[b_i]:
        cnt+=b[b_i]
        b_i+=1
        ans+=1
    elif a[a_i]<b[b_i]:
        cnt+=a[a_i]
        a_i+=1
        ans+=1
    # print(cnt, a_i, b_i, ans)

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n,m,k=rm()
a=rl()
b=rl()
c=a+b
c.sort()
i=0;lc=len(c);cnt=0
while i<lc and k>0:
    if c[i]<=k:
        cnt+=1
        k-=c[i]
        i+=1
    else:
        break
print(cnt)

Submission status: Wrong Answer

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


ans = 0
ans_time = 0
adex = 0
bdex = 0
while True:
    if adex < n and bdex < m:
        if a[adex] < b[bdex]:
            ans_time += a[adex]
            adex += 1
        else:
            ans_time += b[bdex]
            bdex += 1
        ans += 1
    elif adex >= n and bdex < m:
        ans_time += b[bdex]
        bdex += 1
        ans += 1
    elif adex < n and bdex >= m:
        ans_time += a[adex]
        adex += 1
        ans += 1
    else:
        break
        
    if ans_time > k:
        ans -= 1
        break

print(max(0,ans))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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


As = list(accumulate(A))
Bs = list(accumulate(B))

ans = 0
idx = M-1
for i in range(N):    
    while idx != -1 and As[i] + Bs[idx] > K:
        idx -= 1
    num = i + idx + 2
    if A[i] > K:  
        num = 0
    ans = max(ans, num)

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
t = 0
a1 = 0
b1 = 0
while t<k:
    if a1==n:
        t+=b[b1]
        b1+=1
    elif b1==m:
        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:
def main():
    import sys
    import decimal
    input = sys.stdin.readline
    N, M, K = [int(x) for x in input().strip().split()]
    A = [int(x) for x in input().strip().split()] + [float('inf')]
    B = [int(x) for x in input().strip().split()] + [float('inf')]
    cumsum = 0
    ans = decimal.Decimal(0)
    ai = 0
    bi = 0
    while cumsum <= K:
        if A[ai] <= B[bi]:
            if cumsum + A[ai] <= K:
                cumsum += A[ai]
                ans += 1
                ai += 1
            else:
                break
        else:
            if cumsum + B[bi] <= K:
                cumsum += B[bi]
                ans += 1
                bi += 1
            else:
                break
            
    print(ans)

if __name__ == '__main__':
    main()

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

ar = [0]*N
br = [0]*M
ar[0] = A[0]
br[0] = B[0]

for i in range(1, N):
    ar[i] = ar[i-1]+A[i]
for i in range(1, M):
    br[i] = br[i-1]+B[i]

res = bisect.bisect_right(br, K)

for i in range(N):
    if ar[i] < K:
        res = max(i+bisect.bisect_right(br, K-ar[i])+1, res)

print(res)

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_left(B, k)
    ans = max(ans, idx + tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
input = raw_input

n, m, k = map(int, input().split(" "))
As = map(int, input().split(" "))
Bs = map(int, input().split(" "))

ai = 0
bi = 0
cost = 0
flag = True
count = 0
a = As[ai]
b = Bs[bi]

while flag:
    if a is not None and b is not None:
        if a < b:
            next_cost = cost + a
            if next_cost <= k:
                cost = next_cost
                count += 1

                ai += 1
                if ai >= n:
                    a = None

            else:
                flag = False
        else:
            next_cost = cost + b
            if next_cost <= k:
                cost = next_cost
                count += 1

                bi += 1
                if bi >= m:
                    b = None

            else:
                flag = False

    elif a is not None:
        next_cost = cost + a
        if next_cost <= k:
            cost = next_cost
            count += 1

            ai += 1
            if ai >= n:
                a = None

        else:
            flag = False

    elif b is not None:
        next_cost = cost + b
        if next_cost <= k:
            cost = next_cost
            count += 1

            bi += 1
            if bi >= m:
                b = None

        else:
            flag = False

    if a is None and b is None:
        flag = False

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

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
t=1
# t=int(input())
for _ in range(t):
    n,m,k=l()
    A=l()
    B=l()
    i=0
    j=0
    B=A[::-1]+B
    pref=[0 for i in range(n+m+1)]
    for i in range(n+m):
        pref[i+1]=pref[i]+B[i]
    ans=0
    for i in range(n+m):
        x=br(pref,pref[i]+k)
        ans=max(ans,x-i-1)
    print(ans)

Submission status: Wrong Answer

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


A1 = [0] * N
B1 = [0] * M
A1[0] = A[0]
B1[0] = B[0]

for i in range(1, N):
    A1[i] = A[i] + A1[i-1]
for i in range(1, M):
    B1[i] = B[i] + B1[i-1]

ans = 0
t = 0

for i in range(N):
    if A1[i] < K:
        j = bisect_right(B1, K-A[i])
        ans = max(ans, i + j+1)
    else:
        break


print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate, permutations

import bisect
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

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

readed = 0
ans = 0
while readed <= K:
    if not A and not B:
        break
    read = 0
    if A and B:
        if A[0] < B[0]:
            read += A.popleft()
        else:
            read += B.popleft()
    elif A:
        read += A.popleft()
    elif B:
        read += B.popleft()
    if readed + read > K:
        break
    readed += read
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from itertools import accumulate

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

accumA = list(accumulate(A))
accumB = list(accumulate(B))
ans = 0
for i in range(N):
    if accumA[i] > K:
        break
    n = i + 1 + bisect(accumB, K - accumA[i])
    ans = max(n, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

    ans = 0
    i_A = 0
    i_B = 0
    time = 0
    while True:
        if i_A == N:
            for i in range(i_B, M):
                time += B[i]
                if time <= K:
                    ans += 1
                else:
                    break
            break
        if i_B == M:
            for i in range(i_A, N):
                time += A[i]
                if time <= K:
                    ans += 1
                else:
                    break
            break

        if A[i_A] < B[i_B]:
            time += A[i_A]
            i_A += 1
        else:
            time += B[i_B]
            i_B += 1

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

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

cnt = 0
t=0
ai=0
bi=0
while t <= K:
    if ai < len(A):
        a = A[ai]
    else:
        a = float('inf')

    if bi < len(B):
        b = B[bi]
    else:
        b = float('inf')

    if min(a,b) == float('inf'):
        break

    if t+min(a,b) > K:
        break

    t+=min(a,b)
    cnt += 1
    if a == min(a,b):
        ai+=1
    else:
        bi+=1


print(cnt)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
a_index = 0
b_index = 0
count = 0

while k > 0:
    a_min = 1e10
    b_min = 1e10
    if a_index < len(a_list):
        a_min = a_list[a_index]
    if b_index < len(b_list):
        b_min = b_list[b_index]

    if a_min == 1e10 and b_min == 1e10 or k < min(a_min, b_min):
        break
    elif a_min < b_min:
        count += 1
        k -= a_min
        a_index += 1
    else:
        count += 1
        k -= b_min
        b_index += 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF = 10**20
def main():
    N,M,K=mi()
    A=deque(mi())
    B=deque(mi())

    k = 0
    ans = 0
    while k <= K and (A or B):
        a = A.popleft() if len(A) > 0 else INF
        b = B.popleft() if len(B) > 0 else INF

        if a < b:
            k += a
            if b != INF:
                B.appendleft(b)
        else:
            k += b
            if a != INF:
                A.appendleft(a)

        if k <= K:
            ans += 1

    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()))
import itertools
x = list(itertools.accumulate(a))
y = list(itertools.accumulate(b))

ans = 0
import bisect
for i in range(n):
    buf = 0
    if k-x[i]>0:buf = i+1
    buf += bisect.bisect(y,max(k-x[i],0))
    ans = max(ans,buf)
print(ans)

Submission status: Wrong Answer

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

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ia, ib = 0, 0
t = 0
cnt = 0
INF = 987654321

while True:
    if a[ia] >= b[ib]:
        if t + b[ib] > k:
            break
        t += b[ib]
        if ib+1 < m:
            ib += 1
        else:
            b[ib] = INF

    elif a[ia] < b[ib]:
        if t + a[ia] > k:
            break
        t += a[ia]
        if ia+1 < n:
            ia += 1
        else:
            a[ia] = INF
    cnt += 1

    if cnt == n+m:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,m,k = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]
aa = 0
bb = 0
sum = 0
ans = 0
while sum <= k:
    if aa < n and bb < m:
        if a[aa] <= b[bb]:
            sum += a[aa]
            aa += 1
        elif b[bb] < a[aa]:
            sum += b[bb]
            bb += 1
        ans += 1
    elif aa >= n and bb < m:
        sum += b[bb]
        bb += 1
        ans += 1
    elif bb >= m and aa < n:
        sum += a[aa]
        aa += 1
        ans += 1
    else:
        ans += 1
        break
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()))

tmp = 0

flag = True
for i in range(N):
    if tmp + A[i] <= K:
        tmp += A[i]
    else:
        flag = False
        break

left = K - tmp

total = i
if flag:
    total += 1

ans = 0
for j in range(M):
    if B[j] <= left:
        total += 1
        left -= B[j]
    else:
        break

ans = total
while i >= 1:
    total -= 1
    left += A[i - 1]
    i -= 1
    while j < M:
        if B[j] <= left:
            total += 1
            left -= B[j]
            j += 1
        else:
            break
    ans = max(ans, total)

print (ans)

Submission status: Wrong Answer

Solution code:
def solve():
    a_idx, b_idx = 0, 0
    ret = 0
    time = 0
    while True:
        if a_idx == len(A) and b_idx == len(B):
            break
        if a_idx == len(A):
            if time + B[b_idx] <= K:
                time += B[b_idx]
                ret += 1
                b_idx += 1
            else:
                break
        elif b_idx == len(B):
            if time + A[a_idx] <= K:
                time += A[a_idx]
                ret += 1
                a_idx += 1
            else:
                break
        else:
            if A[a_idx] < B[b_idx]:
                if time + A[a_idx] <= K:
                    time += A[a_idx]
                    ret += 1
                    a_idx += 1
                else:
                    break
            else:
                if time + B[b_idx] <= K:
                    time += B[b_idx]
                    ret += 1
                    b_idx += 1
                else:
                    break
    print(ret)

if __name__ == "__main__":
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    solve()

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)

count = 0

count_min = 0

while count_min <= k:
    if a and b:
        if a[0] < b[0]:
            count_min += a[0]
            a.popleft()
        else:
            count_min += b[0]
            b.popleft()
    elif a:
        count_min += a[0]
        a.popleft()
    elif b:
        count_min += b[0]
        b.popleft()
    else:
        print(count)
        exit()
    count += 1

print(count-1)

Submission status: Wrong Answer

Solution code:
N, M, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
cnt = 0
for i, x in enumerate(sorted(A + B)):
    if cnt + x > K:
        print(i)
        exit()
    cnt += x

print(N + M)

Submission status: Wrong Answer

Solution code:
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n,m,k = Ri()

a = Ri()
b = Ri()

i,j = 0,0
ans = 0
flag = True
while i < n and j < m:
    if a[i] < b[j]:
        if k >= a[i] :
            ans+=1
            k-=a[i]
            i+=1
        else:
            # print("fs")
            flag = False
            break
    else:
        if k >= b[j]:
            ans+=1
            k-=b[j]
            j+=1
        else:
            # print("fs")
            flag = False
            break

flag = True
while  i < n:
    if a[i] <= k:
        ans+=1
        k-=a[i]
        i+=1
    else:
        flag = False
        break

while  j < m:
    if b[j] <= k:
        ans+=1
        k-=b[j]
        j+=1
    else:
        flag = False
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split());
alist = list(map(int,input().split()));
blist = list(map(int,input().split()));

book = 0;
time = 0;
aa = 0;
bb = 0;
allread = 0;

while True:
    if aa >= n and bb >= m:
        allread = 1;
        break;
    elif aa >= n:
        b = blist[bb];
        a = b + 1;
    elif bb >= m:
        a = alist[aa];
        b = a + 1;
    else:
        a = alist[aa]
        b = blist[bb]
        
    if a >= b:
        time += b;
        bb += 1;
    else:
        time += a;
        aa += 1;
    if time > k:
        break;
    book += 1;
    
print(book);

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=[0]*N
A[0]=a[0]
ans=0
for i in range(N-1):
 A[i+1]=A[i]+a[i+1]
B=[0]*M
B[0]=b[0]
for i in range(M-1):
 B[i+1]=B[i]+b[i+1]
a=[1,2,2,2,3]
for i in range(N):
 if A[i]<K:
  ans=max(bisect.bisect_right(B,K-A[i])+i+1,ans)
ans=max(bisect.bisect_right(B,K),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
import math
import bisect
from collections import deque
def input():
    return sys.stdin.readline()[:-1]

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ii = 0
jj = 0
ans = 0

while k>=0:
    #print(k)
    if ii ==n and jj==m:
        break
    if ii==n:
        k-=b[jj]
        jj+=1
        if k>=0:
            ans +=1
        continue
    if jj==m:
        k-=a[ii]
        ii+=1
        if k>=0:
            ans +=1
        continue
    if a[ii]<b[jj]:
        k-=a[ii]
        ii+=1
        if k>=0:
            ans +=1
    else:
        k-=b[jj]
        jj+=1
        if k>=0:
            ans +=1

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, lim = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
now = 0
cnt = 0

while now < lim:
  if not a and not b:
    break
  elif not a:
    now += b.pop(0)
    cnt += 1
  elif not b:
    now += a.pop(0)
    cnt += 1
  else:
    if min(a[0], b[0]) > lim - now:
      break
    else:
      if a[0] < b[0]:
        now += a.pop(0)
      else:
        now += b.pop(0)
      cnt += 1

print(cnt)

Submission status: Wrong Answer

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

ans = 0
def get_min(a, b):
  if a and b:
    if a[0] < b[0]:
      next_book = a.popleft()
    else:
      next_book = b.popleft()    
  elif a and not b:
    next_book = a.popleft()
  elif not a and b:
    next_book = b.popleft()
  return a, b, next_book
    

while True:
  a, b, next_book = get_min(a,b)
  
  if k - next_book >= 0:
    ans += 1
    k -= next_book
  if not a and not b:
    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(k+1)
b.append(k+1)
rest=k
ans=0
while rest>=a[0] or rest>=b[0]:
  ans+=1
  if a[0]>=b[0]:
    rest-=b.pop(0)
  else:
    rest-=a.pop(0)
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
ans0 = 0
ans1 = 0
for i in range(n):
    if A[i] + ans0 <= k:
        ans0 += A[i]
        ans1 += 1
    else:
        break
ind = ans1-1

jnd = 0
for i in range(m):
    if B[i] + ans0 <= k:
        ans0 += B[i]
        ans1 += 1
        jnd += 1
    else:
        break


ans = ans1
# print(ans)

for i in range(ind, -1, -1):
    ans1 -= 1
    ans0 -= A[ind]
    while jnd < m and ans0 + B[jnd] <= k:
        ans0 += B[jnd]
        jnd += 1
        ans1 += 1
    ans = max(ans, ans1)
print(ans)

Submission status: Wrong Answer

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

ct=0
ans=0
while True:
    if len(A)==0 and len(B)==0:
        print(ans)
        break
    if len(A)==0:
        ct+=B[-1]
        B.pop()
    elif len(B)==0:
        ct+=A[-1]
        A.pop()
    else:
        if A[-1]<B[-1]:
            ct+=A[-1]
            A.pop()
        else:
            ct+=B[-1]
            B.pop()
    ans+=1
    if ct>K:
        ans-=1
        break

    if N+M==ans:
        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()))
books = 0
i,j = 0,0
bsum = 0
while i<n and j<m:
    if a[i]<b[j]:
        bsum += a[i]
        if bsum<=k:
            books += 1
        i += 1
    else:
        bsum += b[j]
        if bsum<=k:
            books += 1
        j += 1
while i<n:
    bsum += a[i]
    if bsum <= k:
        books += 1
    i += 1
while j<m:
    bsum += b[j]
    if bsum <= k:
        books += 1
    j += 1
print(books)

Submission status: Wrong Answer

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

a= list(map(int,input().split())) #n冊

b= list(map(int,input().split())) #m冊
ab=a+b
ab.sort()

ans=0
count=0

if sum(a)+sum(b)<=k:
    ans=len(a)+len(b)
    print(ans)
else:
    for i in range(n+m):
        ans+=ab[i]
        if ans>k:
            break
        else:
            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.append(10**9+10)
B.append(10**9+10)

i_a = 0
i_b = 0
ans = 0
while 1:
    if K < A[i_a] and K < B[i_b]:
        break
    if A[i_a] < B[i_b]:
        K -=A[i_a]
        i_a += 1
    else:
        K -= B[i_b]
        i_b += 1
    ans += 1

print(ans)

Submission status: Wrong Answer

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

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

point=0
while k>0:
    try:
        if len(A)!=0 and len(B)!=0:
            if A[0]>B[0]:k -=B.popleft()
            else:k -=A.popleft()
        elif len(A)==0:k -=B.popleft()
        elif len(B)==0:k -=A.popleft()

        if k>=0:point +=1
        else:break
    except:break
print(point)

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

book = sorted(A + B)[::-1]
now = 0
ans = 0
# print(book)
while now <= K:
    if len(book) == 0:
        ans += 1
        break
    nowbook = book.pop()
    now += nowbook
    ans += 1
    # print(now, ans)
print(ans - 1)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

A=list(accumulate(a))
B=list(accumulate(b))
ans=1+bisect.bisect_right(B,k)
for i in range(len(a)):
    r = (k-A[i])
    if r<=0:
        break
    #print(r,bisect.bisect_left(B,r))
    #print(B[bisect.bisect_left(B,r)])
    ans=max(ans,i+1+bisect.bisect_right(B,r))
print(ans)