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 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:
    atop = a[0] if a else 10**10
    btop = b[0] if b else 10**10

    if atop == 10**9 and btop == 10**9:
        break

    if atop < btop:
        if tot + atop <= k:
            tot += a.popleft()
            count += 1
        else:
            break
    else:
        if tot + btop <= k:
            tot += b.popleft()
            count += 1
        else:
            break
print(count)

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
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()))
    i = 0
    j = 0
    ans = 0
    time = 0
    while 1:
        if i == N and j == M:
            break
        elif i == N:
            time += B[j]
            j += 1
        elif j == M:
            time += A[i]
            i += 1
        else:
            if A[i] <= B[j]:
                time += A[i]
                i += 1
            else:
                time += B[j]
                j += 1
        if time > K:
            break
        else:
            ans += 1
    print(ans)
        


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    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
    t = 0
    while True:
        if i >= N and  j >= M:
            break
        elif j >= M and t + A[i] <= K:
            ans += 1
            t += A[i]
            i += 1
        elif i >= N and t + B[j] <= K:
            ans += 1
            t += B[j]
            j += 1
        elif i >= N or j >= M:
            break
        elif A[i] < B[j] and t + A[i] <= K:
            ans += 1
            t += A[i]
            i += 1
        elif A[i] > B[j] and t + B[j] <= K:
            t += B[j]
            ans += 1
            j += 1
        else:
            break
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
[n,m,k] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.reverse()
b.reverse()
minites = k
c = 0
while k > 0 and (len(a) or len(b)):
    if len(a) > 0 and len(b) > 0:
        if a[-1] < b[-1]:
            k -= a[-1]
            a.pop()
        else:
            k -= b[-1]
            b.pop()
    elif len(a) > 0:
        k -= a[-1]
        a.pop()
    else:
        k -= b[-1]
        b.pop()
    if k >= 0:
        c += 1
print(c)

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

    t = 0
    i, j = 0, 0
    ans = 0
    while t < K:
        a, b = float('inf'), float('inf')
        if i < len(A):
            a = A[i]
        if j < len(B):
            b = B[j]
        if a < b:
            if t + a  <= K:
                i += 1
                ans += 1
                t += a
            else:
                break
        elif b <= a:
            if t + b <= K:
                j += 1
                ans += 1
                t += b
            else:
                break
    return ans

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

Submission status: Wrong Answer

Solution code:
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
m, n, k = rrm()
a = rrm()[::-1]
b = rrm()[::-1]
ans = 0
while True:
    min_ans = min(a[-1] if a else float('inf'), b[-1] if b else float('inf'))
    if k-min_ans>=0:
        ans+=1
        k-=min_ans
        if a and a[-1]==min_ans:
            a.pop()
        else:
            b.pop()
    else:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = [int(v) for v in input().split()]
alist = deque([int(v) for v in input().split()])
blist = deque([int(v) for v in input().split()])

consumed = 0
count = 0

while consumed < k:
    if len(alist) == 0 and len(blist) == 0:
        break
    if len(alist) == 0:
        consume = blist.popleft()
    elif len(blist) == 0:
        consume = alist.popleft()
    elif alist[0] < blist[0]:
        consume = alist.popleft()
    else:
        consume = blist.popleft()
    if consumed + consume <= k:
        count += 1
        consumed += consume

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(10000000000000)
b.append(10000000000000)
total_time = 0

ans = 0
num_a = 0
num_b = 0

while total_time <= k:
    if a[num_a] < b[num_b]:
        total_time += a[num_a]
        num_a += 1
    else:
        total_time += b[num_b]
        num_b += 1
    ans += 1

if total_time > k:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    n,m,k = MII()
    aa = MII()
    bb = MII()
    ab = aa + bb
    ab.sort(reverse=True)
    cnt = 0
    t = 0
    while ab:
        t += ab.pop()
        if t > k:
            break
        cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

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

ans = 0
cnt = 0
while True:
    if a: at = a.popleft()
    if b: bt = b.popleft()
    if at < bt:
        cnt += at
        b.appendleft(bt)
    else:
        cnt += bt
        a.appendleft(at)
    if cnt >= k:
        print(ans)
        exit()
    ans += 1

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, M, K = LI()
    A = LI()
    B = LI()
    t = 0
    cnt = 0
    ai = 0
    bi = 0

    while t < K and ai < N and bi < M:
        if A[ai] < B[bi]:
            t += A[ai]
            ai += 1
        else:
            t += B[bi]
            bi += 1
        cnt += 1

    if ai == N and bi < M:
        while t < K and bi < M:
            t += B[bi]
            bi += 1
            cnt += 1
        if t > K:
            cnt -= 1
        print(cnt)
        return

    if ai < N and bi == M:
        while t < K and ai < N:
            t += A[ai]
            ai += 1
            cnt += 1
        if t > K:
            cnt -= 1
        print(cnt)
        return
    if t > K:
        cnt -= 1
    print(cnt)



main()

Submission status: Wrong Answer

Solution code:
def hoge():
    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]

    a = 0
    while True:
        if len(A) != 0 and (len(B) == 0 or A[-1] < B[-1]):
            if K < A[-1]:
                return a
            a += 1
            K -= A.pop()
        elif len(B) != 0:
            if K < B[-1]:
                return a
            a += 1
            K -= B.pop()
        else:
            return a

print(hoge())

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

total = 0
ans = 0
while True:
    if len(a) > 0:
        c = a.popleft()
    if len(b) > 0:
        d = b.popleft()
    if len(a) == 0 and len(b) == 0:
        break

    if c <= d:
        if total + c > k: break
        b.appendleft(d)
        total += c
        ans += 1
    else:
        if total + d > k: break
        a.appendleft(c)
        total += d
        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()))

ai = 0
bi = 0
cnt = 0

while True:
    if ai == n and bi == m:
        break
    if ai == n:
        if k - b[bi] < 0:
            break
        k -= b[bi]
        cnt += 1
        bi += 1
        continue
    if bi == m:
        if k - a[ai] < 0:
            break
        k -= a[ai]
        cnt += 1
        ai += 1
        continue
    if a[ai] < b[bi] :
        if k - a[ai] < 0:
            break
        k -= a[ai]
        cnt += 1
        ai += 1
        continue
    elif a[ai] >= b[bi]:
        if k - b[bi] < 0:
            break
        k -= b[bi]
        cnt += 1
        bi += 1
        continue
    break
print(cnt)

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)
t = 0
ans = 0
while t <= K:
  if len(A) == 0 and len(B) == 0:
    break
  if len(A) == 0:
    if t + B[0] <= K:
      t += B.popleft()
      ans += 1
    else:
      break
    continue
  elif len(B) == 0:
    if t + A[0] <= K:
      t += A.popleft()
      ans += 1
    else:
      break
    continue
  if A[0] <= B[0]:
    if t + A[0] <= K:
      t += A.popleft()
      ans += 1
    else:
      break
  else:
    if t + B[0] <= K:
      t += B.popleft()
      ans += 1
    else:
      break
  if t > K:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = (int(x) for x in input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
su = a + b
su.sort()
if sum(su)<=k:
    print(n+m)
else:
    sum_time = 0
    count = 0
    while sum_time<=k:
        sum_time+=su[count]
        count+=1
    print(count-1)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A = deque(A)
B = deque(B)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
def solve():
    ans = 0
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))+[float('inf')]
    B = list(map(int, input().split()))+[float('inf')]
    t = 0
    A = deque(A)
    B = deque(B)
    while True:
        if A[0]<B[0]:
            if t+A[0]<=K:
                t += A[0]
                A.popleft()
            else:
                break
        else:
            if t+B[0]<=K:
                t += B[0]
                B.popleft()
            else:
                break
        ans += 1
    return ans
print(solve())

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

a = 0
b = 0

while True:
    if K<0:
        break
    if a==len(A):
        if b==len(B):
            a += 1
            break
        else:
            K -= B[b]
            b += 1
    elif b==len(B):
        K -= A[a]
        a += 1
    else:
        if A[a]>B[b]:
            K -= B[b]
            b += 1
        else:
            K -= A[a]
            a += 1
    

print(a+b-1)

Submission status: Wrong Answer

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

now=0
ans=0
a_flag=0
b_flag=0
a_now=0
b_now=0
while now<=k:
    if (a_flag==0 and b_flag==0):
        if (a[a_now]<b[b_now]):
            now+=a[a_now]
            if (now>k):
                break
            ans+=1
            a_now+=1
            if (a_now>=n):
                a_flag=1
        elif (a[a_now]>=b[b_now]):
            now+=b[b_now]
            if (now>k):
                break
            ans+=1
            b_now+=1
            if (b_now>=m):
                b_flag=1
    elif (a_flag==1 and b_flag==1):
        break
    elif (a_flag==1 and b_flag==0):
        now+=b[b_now]
        if (now>k):
            break
        ans+=1
        b_now+=1
        if (b_now>=m):
            b_flag=1
    else:
        now+=a[a_now]
        if (now>k):
            break
        ans+=1
        a_now+=1
        if (a_now>=n):
            a_flag=1
        
        
    
print(ans)

Submission status: Wrong Answer

Solution code:
def c_tsundoku():
    N, M, K = [int(i) for i in input().split()]
    A = sorted([int(i) for i in input().split()], reverse=True)
    B = sorted([int(i) for i in input().split()], reverse=True)

    time = 0
    ans = 0
    for _ in range(M + N):
        if time > K:
            ans -= 1
            break

        a = float('inf') if len(A) == 0 else A[-1]
        b = float('inf') if len(B) == 0 else B[-1]

        if a < b:
            t = A.pop()
            time += t
            ans += 1
        else:
            t = B.pop()
            time += t
            ans += 1
    return ans

print(c_tsundoku())

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()))
sumab = 0
for i in range(n):
    sumab += a[i]
    if sumab > k:
        break
for i in range(m):
    sumab += b[i]
    if sumab > k:
        break
if sumab <= k:
    print(n+m)
    exit()
count = 0
tmp = 0
i = 0
j = 0
while True:
    if i == n:
        if k >= tmp + b[j]:
            tmp+=b[j]
            count+=1
            j+=1
        else:
            break
    elif j == m:
        if k >= tmp + a[i]:
            tmp+=a[i]
            count+=1
            i+=1
        else:
            break
    elif a[i] < b[j]:
        if  k >= tmp + a[i]:
            tmp+=a[i]
            count+=1
            i+=1
        else:
            break
    elif b[j] <= a[i]:
        if k >= tmp + b[j]:
            tmp+=b[j]
            count+=1
            j+=1
        else:
            break
print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
A, B = deque(A), deque(B)
ans = 0
while K > 0:
    if A and B:
        if A[0] <= K and B[0] <= K:
            if A[0] <= B[0]: K -= A.popleft()
            else: K -= B.popleft()
            ans += 1
        elif A[0] <= K and B[0] > K: K -= A.popleft(); ans += 1
        elif B[0] <= K and A[0] > K: K -= B.popleft(); ans += 1
        else: break
    elif A:
        if A[0] <= K: K -= A.popleft(); ans += 1
        else: break
    elif B:
        if B[0] <= K: K -= B.popleft(); ans += 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(" ")))

i,j,t=0,0,0
count=0
stop=False
while(t<k and not stop):
    if i<len(a) and j<len(b):
        if a[i]<b[j]:
            t+=a[i]
            i+=1
        else:
            t+=b[j]
            j+=1
        count+=1
    else:
        if i<len(a):
            t+=a[i]
            i+=1
            count+=1
        else:
            if j<len(b):
                t+=b[j]
                j+=1
                count+=1
            else:
                stop=True
if t>k:
    count-=1
print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
AB = A + B
AB.sort()
l = len(AB)
ans = 0
for i in range(l):
    if K - AB[i] >= 0:
        K = K - AB[i]
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
ls_a = list(map(int,input().split()))
ls_b = list(map(int,input().split()))
ls = ls_a + ls_b
ls.sort()

ans = 0
m = 0
for i in range(len(ls)):
  m += ls[i]
  if m > K:
    print(ans)
    break
  else:
    ans += 1
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
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 INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

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

A = [INF] + A[::-1]
B = [INF] + B[::-1]
ans = 0
while 1:
    if A[-1] > B[-1]:
        A, B = B, A
    if K >= A[-1]:
        K -= A.pop()
        ans += 1
    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 = LIST()
B = 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(cnt-1)

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()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
ans = 0
for i in range(n):
    if a[i] < k:
        ans = max(ans,i+1 + bisect.bisect_left(b,k-a[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n):
  acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
  acum2.append(acum2[-1]+arr2[i])
ans=0
for i in range(1,n+1):
  if acum1[i]>k:
    break
  ans=max(ans,i+bisect.bisect_right(acum2,k-acum1[i])-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
import bisect

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, M, K = inm()
A = inl()
B = inl()


def solve():
    acum = accumulate(A)
    bcum = list(accumulate(B))
    ans = 0
    for i, x in enumerate(acum):
        if x > K:
            break

        j = bisect.bisect_right(bcum, K - x)
        s = i + 1 + j
        if ans < s:
            ans = s

    return ans


print(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()))
ans = 0
t = 0
A = 0
B = 0
while t < k:
    if A < n and B < m:
        if a[A] <= b[B]:
            t += a[A]
            if t > k:
                break
            A += 1
            ans += 1
        else:
            t += b[B]
            if t > k:
                break
            B += 1
            ans += 1
    elif B < m:
        t += b[B]
        if t > k:
                break
        B += 1
        ans += 1
    elif A < n:
        t += a[A]
        if t > k:
                break
        A += 1
        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()))
INF=10**12
A.append(INF)
B.append(INF)
A=A[::-1]
B=B[::-1]
for i in range(N+M+1):
  if A[-1]<=B[-1]:
    if K<A[-1]:
      print(i)
      exit()
    K-=A[-1]
    del A[-1]
  else:
    if K<B[-1]:
      print(i)
      exit()
    K-=B[-1]
    del B[-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
t=0
while a or b:
  if not a:
    t+=b.pop()
  elif not b:
    t+=a.pop()
  elif a[-1]>b[-1]:
    t+=b.pop()
  else:
    t+=a.pop()
  if t>k:
    break
  elif t==k:
    ans+=1
    break
  else:
    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_acc=[0]
B_acc=[0]

for a in A:
    A_acc.append(a+A_acc[-1])
for b in B:
    B_acc.append(b+B_acc[-1])

ans=0
for i in range(len(A_acc)):
    a_time = A_acc[i]
    remain = K-a_time
    if remain>0:
        idx = bisect.bisect_left(B_acc,remain)
        ans=max(ans,i+idx-1)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=[0]+list(map(int,input().split()))
for i in range(n):
	a[i+1]+=a[i]
for i in range(m):
	b[i+1]+=b[i]
from bisect import bisect_right
ans=0
for i in range(n+1):
	if k-a[i]>0:
		r=bisect_right(b,k-a[i])
		ans=max(r+i-1,ans)
	else:
		break
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC172-C
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())))

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

            
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,m,k = map(int,readline().split())
*a, = map(int,readline().split())
*b, = map(int,readline().split())

from itertools import accumulate

a = list(accumulate(a))
b = list(accumulate(b))

from bisect import bisect_right

ans = 0
for i,bi in enumerate(b):
    if bi > k: break
    r = i+1 + bisect_right(a,k-bi)
    ans = max(ans,r)


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()))
k=0
a=0
b=0
ans=0
while k<=K:
    if a<N and b<M:
        if A[a]<=B[b]:
            k+=A[a]
            ans+=1
            a+=1
        else:
            k+=B[b]
            ans+=1
            b+=1
    elif a<N:
        k+=A[a]
        ans+=1
        a+=1
    elif b<M:
        k+=B[b]
        ans+=1
        b+=1
    else:
        break
if k>K:
    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()))
nowa = 0
nowb = 0
ans = 0
while k >= 0:
	if nowa < n and nowb < m:
		if a[nowa] < b[nowb]:
			k -= a[nowa]
			nowa += 1
			ans += 1
		else:
			k -= b[nowb]
			nowb += 1
			ans += 1
	elif nowa < n:
		k -= a[nowa]
		nowa += 1
		ans += 1
	elif nowb < m:
		k -= b[nowb]
		nowb += 1
		ans += 1
	else:
		break
	if k < 0:
		ans -= 1
		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()))
c = [0] + list(reversed(b)) + a
for i in range(n + m):
    c[i + 1] += c[i]
r = m
ans = 0
for l in range(m):
    while r <= n + m and c[r] - c[l] <= k:
        ans = max(ans, r - l)
        r += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


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


def main():
    _, _, k = _ia()
    a = list(_ia())
    a += list(_ia())
    a.sort()
    s = 0
    cnt = 0
    for ai in a:
        s += ai
        if s > k:
            break
        cnt += 1

    return cnt


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

Submission status: Wrong Answer

Solution code:
def LI():return list(map(int,input().split()))
from collections import Counter, deque, defaultdict
#from heapq import heappop, heappush
#import numpy as np
#import math
# p=math.pi

INF=10**15
n,m,k=LI()
A=deque(LI()+[INF])
B=deque(LI()+[INF])
cnt=0
while True:
    if A[0]<=B[0]:
        tmp=A.popleft()
    else:
        tmp=B.popleft()
    k-=tmp
    if k<=0:
        break
    cnt+=1
if len(A)==1 and len(B)==1:
    cnt=n+m
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M, K = rl()
A = rl()
B = rl()

A.reverse()
B.reverse()

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

Submission status: Wrong Answer

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

A = [10**10] * 100000 + [int(i) for i in input().split()][::-1]
B = [10**10] * 100000 + [int(i) for i in input().split()][::-1]

t = 0
c = 0
while t < K:
    a, b = A[-1], B[-1]
    if min(a, b) <= (K-t):
        if a <= b:
            t += A.pop()
            c += 1
        else:
            t += B.pop()
            c += 1
    else:
        break
print(c)

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

C = A + B
C.sort()

k = ans = 0
for c in C:
  k += c
  if K <k: break
  ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8


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

    a = 0
    b = 0
    tim = 0
    n_read = 0
    while True:
        if a == N:
            if b == M:
                break
            if tim + B[b] > K:
                break
            tim += B[b]
            b += 1
        elif b == M:
            if tim + A[a] > K:
                break
            tim += A[a]
            a += 1
        elif A[a] < B[b]:
            if tim + A[a] > K:
                break
            tim += A[a]
            a += 1
        else:
            if tim + B[b] > K:
                break
            tim += B[b]
            b += 1
        n_read += 1
    
    return n_read


print(main())