Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

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

    read = deque()
    w = 0
    while w <= K:        
        if len(A) == 0 and len(B) == 0:
            break

        if len(A) == 0:
            if w + B[0] <= K:
                read.append(B[0])
                w += B[0]
            else:
                break
            B.pop(0)
            continue

        if len(B) == 0:
            if w + A[0] <= K:
                read.append(A[0])
                w += A[0]
            else:
                break
            A.pop(0)
            continue

        if A[0] < B[0]:
            if w + A[0] <= K:
                read.append(A[0])
                w += A[0]
            else:
                break
            A.pop(0)
        else:
            if w + B[0] <= K:
                read.append(B[0])
                w += B[0]
            else:
                break
            B.pop(0)

    print(len(read))


resolve()

Submission status: Wrong Answer

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

read_time = 0
count = 0
i = 0
j = 0
while True:
  if i > N - 1 and j > M - 1:
    break
  elif j > M - 1:
    next_book = A[i]
    i += 1
  elif i > N - 1:
    next_book = B[j]
    j += 1
  elif A[i] <= B[j]:
    next_book = A[i]
    i += 1
  else:
    next_book = B[j]
    j += 1
  read_time += next_book 
  if K >= read_time:
    count += 1
  else:
    break 

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right

n,m,k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

a_cumsum = list(accumulate(a_list))

b_cumsum = list(accumulate(b_list))

ans=0
for i in range(n):
  if k<a_cumsum[i]:
    continue
  b_max=k-a_cumsum[i]
  b_index = max(bisect_right(b_cumsum, b_max)-1,0)  
  koho=i+1+b_index+1
  ans = max(ans,koho)

for i in range(m):
  if k<b_cumsum[i]:
    continue
  a_max=k-b_cumsum[i]
  a_index = max(bisect_right(a_cumsum, a_max)-1,0)  
  koho=i+1+a_index+1
  ans = max(ans,koho)
  
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
aa=list(accumulate(a))
bb=list(accumulate(b))

from bisect import bisect_left,bisect

kmax=0
for i in range(n):
    if k<=aa[i]:
        break
    kk=k-aa[i]
    k2=bisect(bb,kk)
    print(i,k2)
    kmax=max(kmax,k2+i+1)

print(kmax)

Submission status: Wrong Answer

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

time = 0
for cnt in range(N+M):
  if As[0] < Bs[0]:
    a,b = 0,1
  else:
    a,b = 1,0
  time += ALL[a][0]
  del ALL[a][0]
  if ALL[a] == []:
    ALL[a].append(10**10)
  if time > K:
    print(cnt)
    break
else:
  print(N+M)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time = 0
count = 0
i = 0
j = 0
A = a[0]
B = b[0]
while i <n or j <m:
    if A<=B:
        time += A
        i += 1
        if i < n:
            A = a[i]
        else:
            A = 10 ** 10
    else:
        time += B
        j += 1
        if j < m:
            B = b[j]
        else:
            B = 10 ** 10
    if time > k:
        break
    count += 1

print(count)

Submission status: Wrong Answer

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

x = [0]
for i in range(len(a) + len(b)):
    num = 0
    if len(a) == 0:
        num = b.pop(0)
    elif len(b) == 0:
        num = a.pop(0)
    elif a[0] < b[0]:
        num = a.pop(0)
    else:
        num = b.pop(0)
    x.append(num + x[i])

x.pop(0)

cnt = 0
for i in range(len(x)):
    if x[i] <= k:
        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()))

# まずaを全部読む
# 全部読めたならbも読む
# 最後の本を捨てて、それがなければどこまでいけるかを試す

ans = 0
cost = 0
b_i = 0
if not (a[0] >= k and b[0] >= k):
  while 1:
    if cost > k:
      break
    ans += 1
    if ans >= n:
      if ans-n>=m:
        break
      cost += b[n-ans]
      b_i += 1
    else:
      cost += a[ans]

  max_ans = ans
  if b_i == 0:
    for i in range(ans-1,-1,-1):
      ans -= 1
      cost -= a[i]
      while cost <= k and b_i < m:
        ans += 1
        cost += b[b_i]
        b_i += 1
      max_ans = max(max_ans, ans)
  else:
    for i in range(n-1,-1,-1):
      ans -= 1
      cost -= a[i]
      while cost <= k and b_i < m:
        ans += 1
        cost += b[b_i]
        b_i += 1
      max_ans = max(max_ans, ans)

  print(max_ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
    N, M, K = map(int, readline().split())
    A = deque([int(i) for i in readline().split()])
    B = deque([int(i) for i in readline().split()])
    cnt = 0
    while (len(A) > 0) or (len(B) > 0): 
        if (len(A) > 0) and (len(B)) > 0:
            a = A.popleft()
            b = B.popleft()
            if a <= b:
                K -= a
                B.appendleft(b)
                if K >= 0:
                    cnt += 1
            else:
                K -= b
                A.appendleft(a)
                if K >= 0:
                    cnt += 1
        elif (len(A) > 0) and (len(B) == 0):
            a = A.popleft()
            K -= a
            if K >= 0:
                cnt += 1
        elif (len(A) == 0) and (len(B) > 0):
            b = B.popleft()
            K -= b
            if K >= 0:
                cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()

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

aa = list(accumulate(a))
ab = list(accumulate(b))
ans = 0
for i in range(n):
    for j in range(m):
        if aa[i] + ab[j] <= k:
            ans = i+j+2

print(ans)

Submission status: Wrong Answer

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

a_li = [0] + a_li
b_li = [0] + b_li

time = 0
ans = 0
a = 0
temp = 0

a_wa = [0] * (n+10)
b_wa = [0] * (m+10)

s = 0
for i in range(n+1):
    s += a_li[i]
    a_wa[i] = s

s = 0
for i in range(m+1):
    s += b_li[i]
    b_wa[i] = s
    

for i in range(n+1):
    for j in range(min(ans-temp, m), m+1):
        time = a_wa[i] + b_wa[j]
        if time <= k:
            ans = max(ans, i+j)
            temp = i
        else:
            break
            
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

ans = 0
for i in range(200000):

    try:
        K = K - A[i]
        if K < 0:
            break
        ans = ans + 1
    except:
        pass

    try:
        K = K -B[i]
        if K < 0:
            break
        ans = ans + 1
    except:
        pass
    
    if K <= 0:
        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()))

cnt = 0
i = 0
j = 0
total = 0

while True:
  if i >= len(A):
    for c in range(j,len(B)):
      total += B[c]
      cnt += 1
      if total > K:
        print(cnt - 1)
        exit()
      elif total == K:
        print(cnt)
        exit()
          
  if j >= len(B):
    for d in range(i,len(A)):
      total += A[d]
      cnt += 1
      if total > K:
        print(cnt - 1)
        exit()
      elif total == K:
        print(cnt)
        exit()
        
  if A[i] < B[j]:
    total += A[i]
    i += 1
    cnt += 1
  else:
    total += B[j]
    j += 1
    cnt += 1
  
  if total > K:
    print(cnt - 1)
    exit()
  elif total == K:
    print(cnt)
    exit()

Submission status: Wrong Answer

Solution code:
def main():
  M, N, K = map(int, input().split())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  spent_time = 0
  count = 0
  
  while(True):
    #print(len(A), len(B))
    if len(A) == 0 and len(B) == 0:
      break
    elif len(B) == 0:
      temp = A.pop(0)
    elif len(A) == 0:
      temp = B.pop(0)
    elif A[0] <= B[0]:
      temp = A.pop(0)
    elif A[0] > B[0]:
      temp = B.pop(0)
    
    if spent_time + temp > K:
      break
    spent_time = spent_time + temp
    count += 1
  
  #print('----')
  #print(spent_time)
  print(count)
  
main()

Submission status: Wrong Answer

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

i,j=0,0
lA,lB=len(A),len(B)

while True:
  if K<=0:
    break
  if A[i]<=B[j] and i<lA:
    K-=A[i]
    i+=1  
  elif B[j]<A[i] and j<lB:
    K-=B[j]
    j+=1
  if i>=lA and K>0:
    while j<lB and K>0:
      K-=B[j]
      j+=1
  elif j>=lB and K>0:
    while i<lA and K>0:
      K-=A[i]
      i+=1

count=i+j-1 if K<0 else i+j
print(count)

Submission status: Wrong Answer

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

a_count = 0
b_count = 0
ans = 0
time = 0
flag = True
while flag:
    ans+=1
    if a_count < n and b_count < m:
        if a[a_count] < b[b_count]:
            time += a[a_count]
            a_count+=1

        else:

            time += b[b_count]
            b_count+=1

    elif a_count < n and b_count >= m:
        time += a[a_count]
        a_count+=1
    elif a_count >= n and b_count <m:
        time += b[b_count]
        b_count += 1
    else:
        flag = False    
    if time>k:
        
        flag = False

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()))
time = 0
count = 0
Ain = 0
Bin = 0
lenA = len(A)
lenB = len(B) 
if(min(min(A),min(B))>K):
    print(0)
    exit()
while time<=K:
    
    if((lenA!=Ain) and (lenB!=Bin)):
        if(A[Ain]<B[Bin]):
            time+= A[Ain]
            Ain+=1
            count +=1
        elif(A[Ain]>B[Bin]):
            time += B[Bin]
            Bin+=1
            count+=1
    elif((lenA==Ain) and (lenB==Bin)):
        break
    elif(lenA==Ain):
        time += B[Bin]
        Bin += 1
        count += 1
    elif(lenB==Bin):
        time += A[Ain]
        Ain += 1
        count += 1
if(time == K):
    print(count)
else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
def A(x):
  return x + x**2 + x**3


def B(s, t):
  ans = 0
  for i in range(len(s)):
    if s[i] != t[i]:
      ans += 1
  return ans


def C(n, m, k, a, b):
  ans = 0
  while k > 0:
    if a and b:
      if a[0] < b[0]:
        k -= a[0]
        a.pop()
      else:
        k -= b[0]
        b.pop()
    elif a:
      k -= a[0]
      a.pop()
    elif b:
      k -= b[0]
      b.pop()
    else:
      break
    if k >= 0:
      ans += 1
  return ans


def main():
  n, m, k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  print(C(n, m, k, a, b))


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
for i in range(n + m):
    if len(A) >= 1 and len(B) >= 1:
        if k >= A[0] or k >= B[0]:
            if A[0] >= B[0]:
                cnt += 1
                k = k - B[0]
                B.pop(0)
            else:
                cnt += 1
                k = k - A[0]
                A.pop(0)
    elif len (A) >= 1 and len(B) == 0:
        if k >= A[0]:
            cnt += 1
            k = k - A[0]
            A.pop(0)
        else:
            break
    elif len (B) >= 1 and len(A) == 0:
        if k >= B[0]:
            cnt += 1
            k = k - B[0]
            B.pop(0)
        else:
            break
    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()))

def 操作(A,B,N,M):
    MAX=0
    s=0
    for i in range(N):
        s+=A[i]
        if s>=K:
            break
        S=s
        for j in range(M):
            S+=B[j]
            if S<=K:
                if i+j+2>MAX:
                    MAX=i+j+2
                else:
                    break
    return MAX

if N>=M:
    print(操作(A,B,N,M))
else:
    print(操作(B,A,M,N))

Submission status: Wrong Answer

Solution code:
import copy
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()))
a = 0
b = 0

tmp = 0
ans = 0
# for i in range(200000):
#     if A[a] < B[b]:
#         if tmp <= K:
#             tmp += A[a]
#             ans += 1
#             a += 1
#     elif A[a] > B[b]:
#         if tmp <= K:
#             tmp += B[b]
#             ans += 1
#             b += 1
#     if a > len(A)-1 or b > len(B)-1:
#         break
fa = False
fb = False
flag = False
while len(A) != 0 and len(B) != 0:
    AA = copy.copy(A)
    BB = copy.copy(B)
    if len(A) != 0:
        a = AA.pop(0)
        fa = True
    if len(B) != 0:
        b = BB.pop(0)
        fb = True
    if fa and fb:
        if a<=b:
            tmp += a
            ans += 1
            A = AA
        else:
            tmp += b
            ans += 1
            B = BB
    else:
        if fa:
            tmp += a
            ans += 1
            A = AA
        if fb:
            tmp += b
            ans += 1
            B = BB

    if tmp > K or ( len(A)==0 and len(B)==0):
        if len(A)==0 and len(B)==0:
            flag = True
        break
    fa = False
    fb = False
    
    #print(tmp)
    
if flag:
    print(ans)
else:
    print(ans-1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
An, Bn, t = [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()]


idxA = 0
idxB = 0

cnt = 0

for i in range(An + Bn):
	if t < 0 : break

	if An > i :
		t -= A[idxA]
		if t < 0 : break
		cnt += 1
		idxA += 1

	if Bn > i :
		t -= B[idxB]
		if t < 0 : break
		cnt += 1
		idxB += 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()))

read_time = 0
books = 0
while True:
    if B_list == []:
        if A_list == []:
            break
        read_time += A_list[0]
        if read_time > K:
            break
        books += 1
        del A_list[0]
    elif A_list == []:
        read_time += B_list[0]
        if read_time > K:
            break
        books += 1
        del B_list[0]
    elif A_list[0] < B_list[0]:
        read_time += A_list[0]
        if read_time > K:
            break
        books += 1
        del A_list[0]    
    elif A_list[0] >= B_list[0]:
        read_time += B_list[0]
        if read_time > K:
            break
        books += 1
        del B_list[0]

print(books)

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.reverse()
B.reverse()


jikan=0
count=0
while True:
    if len(A)==0 and len(B)==0:
        count+=1
        break

    elif len(A)==0:
        jikan+=B[-1]
        count+=1
        del B[-1]
        if jikan>K:
            break

    elif len(B)==0:
        jikan+=A[-1]
        count+=1
        del A[-1]
        if jikan>K:
            break
    else:
        if A[-1] <= B[-1]:
            jikan+=A[-1]
            count+=1
            del A[-1]
        if jikan>K:
            break
        else:
            jikan+=B[-1]
            count+=1
            del B[-1]
            if jikan>K:
                break
    #print('A,B:', A,B)

print(count-1)

Submission status: Wrong Answer

Solution code:


def tsundoku(a, b, k):
    n = len(a)
    m = len(b)
    count = 0
    while (a and b) and (k > 0):
        if a[0] < b[0]:
            k = k - a.pop(0)
            n -= 1
        else:
            k = k - b.pop(0)
            m -= 1
        count += 1

    if k > 0 and (a or b):
        temp = a if a else b
        while temp and k > 0:
            k = k - temp.pop(0)
            count += 1
    if k < 0:
        count -= 1
    return count

def start():
    N, M, K = [int(v) for v in input().split(" ")]
    A = [int(v) for v in input().split(" ")]
    B = [int(v) for v in input().split(" ")]
    res = tsundoku(A, B, K)
    print(res, end="")

start()

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()))
a1=[0 for i in range(n)]
b1=[0 for i in range(m)]
a1[0]=a[0]
b1[0]=b[0]
for i in range(1,n):
    a1[i]=a1[i-1]+a[i]
for i in range(1,m):
    b1[i]=b1[i-1]+b[i]
l=0
for i in range(0,n):
    if a1[i]>k:
        l=i
        break
else:
    l=n
ans=l
for i in reversed(range(0,l)):
    s=a1[i]
    for j in range(m):
        if s+b1[j]>k:
            if i+j+1>ans:
                ans=i+j+1
            break
    else:
      if i+1+m>ans:
          ans=i+1+m
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, p = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = n + m
j, k = 0, 0
c = []
for i in range(l):
  if a[j:j+1] < b[k:k+1]:
    cc = a[j:j+1]
    c.append(cc)
    j += 1
  else:
    cc = b[k:k+1]
    c.append(cc)
    k += 1
  if (j == n):
    for j in range(m - k):
      cc = b[k:k+1]
      c.append(cc)
      k += 1
    break
  if (k == m):
    for j in range(n - j):
      cc = a[j:j+1]
      c.append(cc)
      j += 1
    break
sumc = 0
countc = 0
for i in range(len(c)):
  sumc += int(c[i][0])
  if sumc > p:
    break
  countc += 1
print(countc)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

A_sum = np.array( list(map(lambda i: np.sum(A[:i+1]), range(N))) )
B_sum = np.array( list(map(lambda i: np.sum(B[:i+1]), range(M))) )

A_sum_lim = A_sum[np.where(A_sum<=K)]
B_sum_lim = B_sum[np.where(B_sum<=K)]
ans = 0

for i in range(len(A_sum_lim)-1,0,-1):
    for j in range(len(B_sum_lim)):
        time = A_sum_lim[i] + B_sum_lim[j]
        if time<=K and ans<i+j+2:
            ans = i+j+2
        if time>K:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    ans = 0
    total = 0
    for a in A:
        if a + total <= K:
            ans += 1
            total += a
        else:
            break
    maxans = ans
    anow = N - 1
    for b in B:
        total += b
        while total > K:
            total -= A[anow]
            ans -= 1
            if ans == -1:
                break
        ans += 1
        maxans = max(maxans, ans)
    print(maxans)

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()))
t = 0
n = 0

while K > t :
    if len(A)>0 and len(B)>0 :
        if A[0] <= B[0] :
            t += A[0]
            n += 1
            del A[0]
        else :
            t +=B[0]
            n += 1
            del B[0]
    elif len(A)== 0 :
        t += B[0]
        n += 1
        del B[0]
    else :
        t += A[0]
        n += 1
        del A[0]

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

time = 0
cnt = 0
ans = 0
b = []

for i in B:
    if i+time>K:
        break
    time += i
    cnt += 1
    b.append(i)

b.reverse()
# print(b)
# print(cnt)
bi = 0
for i in range(N):
    if time+A[i] <= K:
        cnt += 1
        time += A[i]
    else:
        if len(b)-1 >= bi:
            if A[i] <= b[bi]:
                time -= b[bi]-A[i]
                bi += 1
        else:
            break
            # print("a")
            # print(time+A[i])
       
    # print(time)


print(cnt)

'''
5 3 8
5 0 0 1 1
1 2 6
'''

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
num_n = 0
num_m = 0
time = 0
while ans < n+m:
  if num_n == n:
    tmp = b[num_m]
    num_m += 1
  elif num_m == m:
    tmp = a[num_n]
    num_n += 1
  else:
    if a[num_n] >= b[num_m]:
      tmp = b[num_m]
      num_m += 1
    else:
      tmp = a[num_n]
      num_n += 1
      
  if time + tmp < k:
    time += tmp
    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()))
x = a + b
x.sort()
sum = 0
for i in range(len(x)):
    sum += x[i]
    if sum > k:
        print(i)
        exit()

print(len(x))

Submission status: Wrong Answer

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

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

ind=bisect.bisect_left(a,k)
j=0
ans=ind-1
for i in range(ind-1,-1,-1):
    while a[i]+b[j]>k or a[i]+b[j+1]<=k:
        j+=1
    print(i,j)
    ans=max(ans,i+j)
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(" ")))

que = list()

flag = True
val = 0

while flag:
    if len(A) == 0 and len(B) == 0:
        flag = False
        break
    elif len(A) > 0 and len(B) > 0:
        if A[0] < B[0]:
            val = A.pop(0)
        else:
            val = B.pop(0)
    elif len(A) == 0 and len(B) > 0:
        val = B.pop(0)
    elif len(B) == 0 and len(A) > 0:
        val = A.pop(0)

    if sum(que) + val <= K:
        que.append(val)
    else:
        flag = False
        break


print(len(que))

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

Submission status: Wrong Answer

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

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

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()))
read = 0
time = 0
while time <= K:
    read += 1
    if min(len(A), len(B))!=0:
        if A[0] <= B[0]:
            time += A.pop(0)
        elif B[0] <= A[0]:
            time += B.pop(0)
    elif max(len(A), len(B))!=0:
        if len(A) ==0:
            time += B.pop(0)
        elif len(B) ==0:
            time += A.pop(0)
    else:
        break

print(read-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()))
amount = 0
a_i = 0
b_i = 0
cnt = 0
while True:
    if amount >= k:
        break
    if a_i <= n-1 and b_i <= m-1 and a[a_i] < b[b_i]:
        amount += a[a_i]
        a_i += 1
    elif a_i <= n-1 and b_i > m-1:
        amount += a[a_i]
        a_i += 1
    elif a_i > n-1 and b_i <= m-1:
        amount += b[b_i]
        b_i += 1
    elif a_i > n-1 and b_i > m-1:
        break
    else :
        amount += b[b_i]
        b_i += 1
    if amount <= k:
            cnt += 1
    else :
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
import numpy as np

def binary_search(lis, item):
    low = 0
    high = len(lis) - 1
    inRange = high

    while low <= high:
        mid = (low + high) //2
        guess1 = lis[mid]
        if mid < inRange:
            guess2 = lis[mid+1]
        else:
            return len(lis)
        if guess1 <= item < guess2:
            return mid+1
        if guess1 > item:
            high = mid-1
        else:
            low = mid+1
    return 0

n,m,k = iim()
a = iil()
cuma = []
if a[0] <= k:
    cuma.append(a[0])
    for i in range(n-1):
        num = cuma[-1]+a[i+1]
        if num > k:
            break
        else:
            cuma.append(num)
b = iil()
cumb = []
if b[0] <= k:
    cumb.append(b[0])
    for i in range(m-1):
        num = cumb[-1]+b[i+1]
        if num > k:
            break
        else:
            cumb.append(num)
if len(cuma) > 0:
    cnt = len(cuma)
    ans = cnt+binary_search(cumb,k-cuma[-1])
    #print(k-cuma[-1],binary_search(cumb,k-cuma[-1]))
    for i,item in enumerate(cuma[::-1]):
        tmp = cnt-i
        res = k-item
        plus = binary_search(cumb,res)
        ans = max(ans,tmp+plus)
else:
    ans = binary_search(cumb,k)
print(ans)