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:
n, m, k = map( int, input().split() )
a = list( map( int, input().split() ) )
b = list( map( int, input().split() ) )

a.append( 10 ** 9 + 1 )
b.append( 10 ** 9 + 1 )

i = 0
j = 0
time = 0
read = 0

while True:
    if i == n and j == m:
        break
    elif a[ i ] < b[ j ]:
        if time + a[ i ] > k:
            break
        else:
            time += a[ i ]
            read += 1
            i += 1
    else:
        if time + b[ j ] > k:
            break
        else:
            time += b[ j ]
            read += 1
            j += 1
    
print( read )

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
rl = []

for i in range(n+1) :
    As = sum(al[:i+1])
    if As >= k :
        break
    for j in range(m+1) :
        Bs = sum(bl[:j+1])
        if As + Bs < k :
            rl += [i+j]
        else :
            break

if rl == [] :
    print(0)
else :
    print(max(rl) + 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
read_list = []
cnt = 0

diffvalue = max(n, m) - min(n, m)

# for i in range(diffvalue):
#     if n > m:
#         b_lst.append(999999999)
#     else:
#         a_lst.append(999999999)

# print(a_lst, b_lst)


while sum(read_list) <= k:

    if len(a_lst) == 0:
        a_lst.append(999999999)
    elif len(b_lst) == 0:
        b_lst.append(999999999)

    x = min(a_lst[0], b_lst[0])
    # print(x)
    read_list.append(x)

    if a_lst <= b_lst:
        del a_lst[0]
    else:
        del b_lst[0]

    cnt += 1

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

t = 0
cnt = 0
c1, c2 = A.pop(), B.pop()
while True:
    if t >= K or (t + c1 > K and t + c2 > K):
        break
    if c1 <= c2:
        if t + c1 <= K:
            t += c1
            cnt += 1
            c1 = A.pop() if bool(A) else 100000000000
    else:
        if t + c2 <= K:
            t += c2
            cnt += 1
            c2 = B.pop() if bool(B) else 100000000000

print(cnt)

Submission status: Wrong Answer

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

t = 0
count = 0
while 1:
    # read
    if A and not B:
        t += A.pop()
    elif not A and B:
        t += B.pop()
    elif A and B:
        if A[-1] < B[-1]:
            t += A.pop()
        else:
            t += B.pop()
    else:
        break

    if t > K:
        break
    else:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
##C
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
##print(A+B)
C = A+B
C.sort()
##print(C)
i = 0
goukei = 0
if K >= sum(C):
    print(N+M)
else:
    while goukei <= K: 
        goukei += C[i]
        i += 1
    print(i-1)

Submission status: Wrong Answer

Solution code:
import bisect
#aaa = [0, 80, 230, 310, 460]
#print(bisect.bisect_left(aaa, 460))
#print(bisect.bisect_left(aaa, 459))

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

# 累積和
sa = [0] * (n+1)
for i in range(n):
  sa[i+1] = sa[i] + a[i]
sb = [0] * (m+1)
for i in range(m):
  sb[i+1] = sb[i] + b[i]

#print(sa)
#print(sb)
ans = 0
for ac in range(n+1):
  # i = Aの机からの冊数
  rk = k - sa[ac] # bに使える時間
  if rk <= 0:
    break
  bc = 0
  if rk == sb[m]:
    bc = m
  else:
    bc = bisect.bisect_left(sb, rk) - 1
  #print(rk, bc)
  ans = max(ans, ac+bc)
print(ans)

Submission status: Wrong Answer

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

A_index = 0
B_index = 0
ans = 0
minute = 0
for i in range(N+M):
    if A[A_index] >= B[B_index]:
        minute += B[B_index]
        B_index+=1
        if B_index==M:
            B[B_index-1] = 10**10
        B_index=min(B_index, M-1)

        
    elif A[A_index] <= B[B_index]:
        minute += A[A_index]
        A_index+=1
        if A_index==N:
            A[A_index-1] = 10**10
        A_index=min(A_index, N-1)
    
    if minute > K:
        break
    ans+=1
print(ans)

Submission status: Wrong Answer

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

max = N + M
  #print(max)
sum = 0

for i in range(max):

  if len(a) > 0 and len(b) > 0:
    #print(a[0], b[0])
    if a[0] < b[0]:
      k = a[0]
      a.pop(0)
    else:
      k = b[0]
      b.pop(0)
    
    if KK >= k :
      KK -= k
      sum += 1
    else:
      break
      
  elif len(a) > 0 and len(b) == 0:
    k = a[0]
    
    if KK >= k :
      KK -= k
      sum += 1
      a.pop(0)
    else:
      break
  
  elif len(a) == 0 and len(b) > 0:
    k = b[0]
    
    if KK >= k :
      KK -= k
      sum += 1
      b.pop(0)
    else:
      break
    
  else:
    break
    
  #print(a)
  #print(b)
  #print(KK)
print(sum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

sum = 0
count = 0

i = 0
j = 0


while sum < k:
    if i >= n and j >= m:
        break
    elif i >= n:
        sum += b_list[j]
        j += 1
        count += 1
    elif j >= m:
        sum += a_list[i]
        i += 1
        count += 1
    elif a_list[i] <= b_list[j]:
        sum += a_list[i]
        i += 1
        count += 1
    elif a_list[i] >= b_list[j]:
        sum += b_list[j]
        j += 1
        count += 1
    if sum > k:
        count -= 1
    
print(count)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum_k=0
listAB=A+B
listAB.sort()
n=0
for i in range(len(listAB)):
    if sum_k<=K:
        sum_k+=listAB[i]
        n+=1
    else:
        n-=1
        break
print(n)

Submission status: Wrong Answer

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

nc = 0
mc = 0
cnt = 0
t = 0
while cnt + a[nc] <= k or cnt + b[mc] <= k:
    if a[nc] > b[mc]:
        cnt += b[mc]
        mc += 1
    else:
        cnt += a[nc]
        nc += 1
    t += 1
print(t)

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

a.append(10 ** 10)
b.append(10 ** 10)
na = a.popleft()
nb = b.popleft()

cnt = 0
min = 0
while min <= k:
    if na <= nb:
        cnt += 1
        min += na
        na = a.popleft()
        print(na)
    else:
        cnt += 1
        min += nb
        nb = b.popleft()
        print(nb)
    if na == 10 ** 10 and nb == 10 ** 10:
        cnt += 1
        break
print(cnt-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
time = 0
n = 0
m = 0
for i in range(N+M):
    if n < N and m < M:
        if A[n] <= B[m]:
            time += A[n]
            n += 1
        else:
            time += B[m]
            m += 1
    else:
        if n >= N and m >= M:
            break
        elif n == N and m < M:
            time += B[m]
            m += 1
        elif m == M and n < N:
            time += A[n]
            n += 1
    if time <= K:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
[N,M,K]=list(map(int, input().split()))
alist=list(map(int, input().split()))
blist=list(map(int, input().split()))
clist=alist+blist
clist.sort()

time=0
ans=-1
ci=0
while time<=K :
    ans+=1

    #print(time,ans)
    if ans == len(clist):
        break
    time+=clist[ans]


print(ans)

Submission status: Wrong Answer

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

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

s=0
ac=0
bc=0
max=0

for i in range(n):
  s=s+a[i]
  ac=ac+1
  if s > k:
    s=s-a[i]
    ac=ac-1
    break
for i in range(m):
  s=s+b[i]
  bc=bc+1
  if s > k:
    s=s-b[i]
    bc=bc-1
    break

max=ac+bc

flag=0
while flag==0 and ac!=0:
  ac=ac-1
  s=s-a[ac]
  while s <= k:
    bc=bc+1
    if bc > m:
      flag=1
      break
    s=s+b[bc-1]
  bc=bc-1
  if flag==0:
    s=s-b[bc-1]
  
  if max < ac+bc:
    max=ac+bc
    
print(max)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = list(map(int, input().split()))
As = deque(list(map(int, input().split())))
Bs = deque(list(map(int, input().split())))
total_time = 0
cnt = 0
selected_book = 0

for _ in range(0, N+M):

    if As:
        a_head = As[0]
    else:
        a_head = 10**9
    if Bs:
        b_head = Bs[0]
    else:
        b_head = 10**9

    if a_head > b_head:

        selected_book = Bs.popleft()
    else:
        selected_book = As.popleft()

    total_time += selected_book

    if K >= total_time:
        # print("sel" + str(selected_book))
        # print("tot" + str(total_time))
        cnt += 1

    else:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:

import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

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

a = []
sum_a = 0
for i in A:
    sum_a += i
    a.append(sum_a)

b = []
sum_b = 0
for i in B:
    sum_b += i
    b.append(sum_b)

ans = 0
for i in range(len(a)):
    ai = a[i]
    if ai > K:
        break

    tmp = K - ai

    j = bisect_right(b, tmp) - 1
    if j == -1:
        r = i + 1
    else:
        r = (i + 1) + (j + 1)

    #print(i, j, a, b, ai)   
    if r > ans:
        ans = r

if ans >= 0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A = deque()
li = list(map(int, input().split()))
for a in li: A.append(a)
B = deque()
li = list(map(int, input().split()))
for b in li: B.append(b)


ans = 0
flag = 0
while K >= 0:
    if A[0] <= B[0]:
        t = A.popleft()
    else:
        t = B.popleft()
    K -= t
    ans += 1
    if len(A)*len(B) == 0:
        flag = 1
        break

if flag == 1:
    if len(B) == 0:
        while K >= 0 and len(A) != 0:
            t = A.popleft()
            K -= t
            ans += 1
    elif len(A) == 0:
        while K >= 0 and len(B) != 0:
            t = B.popleft()
            K-= t
            ans += 1
            
if K < 0: 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()))

i_a = 0
i_b = 0

total_time = 0

while True:
    if i_a == N and i_b == M:
        break
    else:
        if i_a == N:
            read_a = False
        elif i_b == M:
            read_a = True
        elif A[i_a] <= B[i_b]:
            read_a = True
        else:
            read_a = False
    
    if read_a:
        if A[i_a] <= K - total_time:
            total_time += A[i_a]
            i_a += 1
        else:
            break
    else:
        if B[i_b] <= K - total_time:
            total_time += B[i_b]
            i_b += 1
        else:
            break

print(int(i_a+i_b))

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    time, ans = 0, 0
    a, b = 0, 0
    for _ in range(n+m):
        if time > k:
            print(ans-1)
            return
        if a < n and b < m:
            if A[a] < B[b]:
                time += A[a]
                a += 1
            else:
                time += B[b]
                b += 1
        elif a == n and b < m:
            time += B[b]
            b += 1
        elif a < n and b == m:
            time += A[a]
            a += 1
        else:
            print(ans)
            return
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect

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

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

ASList = [AList[0]]
for i in range(1,N+1):
  a = ASList[-1] + AList[i]
  ASList.append(a)

BSList = [0,BList[0]]
for i in range(1,M+1):
  a = BSList[-1] + BList[i]
  BSList.append(a)  
  
ans = 0
for i in range(M+2):
  b = BSList[i]
  c = int( K-b )
  if c > 0:
    d = bisect.bisect_left(ASList,c)
    if ASList[d] == c:
      d +=1 
    ans = max(ans,i+d)
  elif c == 0:
  	ans = max(ans,i+d)
  else:
    d = bisect.bisect_left(ASList,K)
    ans = max(ans,d)
  
print(int(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()))

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

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

ans = 0
for i in range(N+1):
    tmp_K = K-aa[i]
    if tmp_K == 0:
        ans = max(ans, i)
    elif tmp_K < 0:
        continue

    if tmp_K >= bb[-1]:
        ans = max(ans, i+M)
        continue

    mn = 0
    mx = M
    while True:
        if mn == mx:
            if tmp_K >= bb[mn]:
                ans = max(ans, i+mn)
            break

        mid = (mn+mx//2)
        if bb[mid] <= tmp_K:
            if mn == mid:
                mn = mid+1
            else:
                mn = mid
            if i+mn <= ans:
                break
        else:
            if mx == mid:
                mx = mid-1
            else:
                mx = mid
print(ans)

Submission status: Wrong Answer

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

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


time = 0
i=0
k=0

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


while True:
    
    if i>=N and not k>=M:
        time += B[k]
        if time >K:
            print(i+k)
            exit()
        k+=1
    elif k>=M and not i>=N:
        time += A[i]
        if time >K:
            print(i+k)
            exit()
        i += 1
    
    else :
        if A[i]>=B[k]:
            time += B[k]
            if time >K:
                print(i+k)
                exit()
            k+=1

        else:
            time += A[i]
            if time >K:
                print(i+k)
                exit()
            i += 1

Submission status: Wrong Answer

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


ai = 0
bi = 0

dp = [0 for i in range(M+N+1)]

for i in range(1, N+M+1):
    if ai == N:
        res = b[bi]
        bi += 1
    elif bi == M:
        res = a[ai]
        ai += 1
    elif a[ai] == b[bi]:
        ra = ai; rb = bi
        while a[ra] == b[rb]:
            ra += 1
            rb += 1
            if ra == N or rb == M:
                res = a[ai]
                ai += 1
                break
            elif a[ra] < b[rb]:
                res = a[ai]
                ai += 1
                break
            elif a[ra] > b[rb]:
                res = b[bi]
                bi += 1
                break
    elif a[ai] < b[bi]:
        res = a[ai]
        ai += 1
    else:
        res = b[bi]
        bi += 1
    dp[i] = dp[i-1] + res

#print(dp)

import bisect
print(bisect.bisect_right(dp, K)-1)

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

    c = a + b
    c.sort()
    sum = 0
    for i in range(len(c)):
        sum += c[i]
        if k < sum:
            return print(i)
    print(len(c))


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()))
books = 0
cost = 0
for i in range(N+M):
    if cost > K:
        break
        
    if len(B) == 0:
        cost += A.pop(0)
        books += 1
    elif len(A) == 0 or A[0] >= B[0]:
        cost += B.pop(0)
        books += 1
    else:
        cost += A.pop(0)
        books += 1
if cost > K:
    print(books-1)
    
elif books <= 0:
    print(0)
else:
    print(books)

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

sum_a = sum(A)
sum_b = sum(B)
time = sum_a + sum_b
ans = n+m

a = [0 for i in range(n)]
count = A[0]
a[0] = count
for i in range(1,n):
    count += A[i]
    a[i] = count

b = [0 for i in range(m)]
count = B[0]
b[0] = count
for i in range(1,m):
    count += B[i]
    b[i] = count

while time > k:
    if n != 0 and m != 0:
        if a[n-1] >= b[m-1]:
            ans -= 1
            time -= A[n-1]
            n -= 1
        else:
            ans -= 1
            time -= B[m-1]
            m -= 1
    elif n == 0 and m != 0:
        ans -= 1
        time -= B[m-1]
        m -= 1
    elif n != 0 and m== 0:
        ans -= 1
        time -= A[n-1]
        n -= 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()))

prefix_A = [0] * (N + 1)
for i, a in enumerate(A, 1):
    prefix_A[i] = prefix_A[i - 1] + a
prefix_B = [0] * (M + 1)
for j, b in enumerate(B, 1):
    prefix_B[j] = prefix_B[j - 1] + b


res = 0
for i in range(1, N + 1):
    cur = prefix_A[i]
    if cur == K:
        res = max(i, res)
    elif cur < K:
        left = 0
        right = M + 1
        while right - left > 1:
            mid = (left + right) // 2
            if cur + prefix_B[mid] <= K:
                left = mid
            else:
                right = mid
        res = max(res, i + left)


print(res)

Submission status: Wrong Answer

Solution code:
def aaa():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = []
    for i,j in zip(a,b):
        c.append(i)
        c.append(j)
    d = 0
    e = 0
    for i in c:
        if i+e < k:
            e += i
            d += 1
        else:
            return d
    return n + m
aaa()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import collections

def input():
    return sys.stdin.readline()

def greedy_reading(n, m, k, a_list, b_list):

    max_books = len(a_list) + len(b_list)

    k_remain = k
    count = 0
    for i in range(max_books):
        if len(a_list) > 0 and len(b_list) > 0:
            if a_list[0] <= b_list[0]:
                if k_remain < a_list[0]:
                    break
                k_remain -= a_list.popleft()
                count += 1
            else:
                if k_remain < b_list[0]:
                    break
                k_remain -= b_list.popleft()
                count += 1
        elif len(a_list) > 0:
            if k_remain < a_list[0]:
                break
            k_remain -= a_list.popleft()
            count += 1
        elif len(b_list) > 0:
            if k_remain < b_list[0]:
                break
            k_remain -= b_list.popleft()
            count += 1


    return count


def resolve():
    n, m, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    a_list = collections.deque(a_list)
    b_list = collections.deque(b_list)
    ans = greedy_reading(n, m, k, a_list, b_list)

    print(ans)
    exit()
    a_sum = 0
    b_sum = 0
    a_num = 0
    b_num = 0
    a_remain = 0
    b_remain = 0
    # Aから
    for i in range(len(a_list)):
        a_sum += a_list[i]
        if a_sum > k:
            a_sum -= a_list[i]
            a_num = i
            break

    if a_num == 0:
        a_num = len(a_list)
        a_remain = k - a_sum

    # B
    for i in range(len(b_list)):
        b_sum += b_list[i]
        if b_sum > k:
            b_sum -= b_list[i]
            b_num = i
            break

    if b_num == 0:
        b_num = len(b_list)
        b_remain = k - b_sum

    # Aオーバーしない
    if a_remain == 0:
        pass









if __name__ == "__main__":
    resolve()

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

time = 0
count = 0
while len(a) > 0 or len(b) > 0:
    if len(a) ==  0:
        book_b = b.popleft()
        time += book_b
        count += 1
    elif len(b) == 0:
        book_a = a.popleft()
        time += book_a
        count+= 1
    elif a[0] > b[0]:
        book_b = b.popleft()
        time += book_b
        count += 1
    else:
        book_a = a.popleft()
        time += book_a
        count += 1
    if time > k:
        count -= 1
        break
    elif time == k:
        break
    
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(float('inf'))
b.append(float('inf'))
at = 0
bt = 0
time = 0
cnt = 0

while time+a[at]<=k or time+b[bt]<=k:
    if a[at] <= b[bt]:
        time += a[at]
        at += 1
        cnt += 1
    elif a[at] > b[bt]:
        time += b[bt]
        bt += 1
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
a,b,c = (int(i) for i in input().split())
N = list(int(a) for a in input().split())
M = list(int(b) for b in input().split())
total = 0
n = 0
m = 0
e = 0
for i in range(a+b):
  if N[n] < M[m] and n < a:
    c -= N[n]
    e += 1
  elif N[n] > M[m] and m < a:
    c -= M[m]
    e += 1
  elif n == a:
    c -= M[m]
    e += 1
  elif m == a:
    c -= N[n]
    e += 1

  if c < 0:
    e -= 1
    break

print(e)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
n,m,s=map(int, stdin.readline().split());M=10**9+2
dn=list(map(int, stdin.readline().split()))+[M]
dm=list(map(int, stdin.readline().split()))+[M]
cn=0;cm=0;cs=0
'''print(dn,dm)'''
for v in dn:
    cs+=v
    if cs>s:
        f=1;cs-=v
        for v1 in dm:
            cs+=v1
            if cs>s:
                f=0
                break
            cn+=1
        if f==0:break
    #print(v)
    cn+=1
cs=0
for v in dm:
    cs+=v
    if cs>s:
        f=1;cs-=v
        for v1 in dn:
            cs+=v1
            if cs>s:
                f=0
                break
            cm+=1
        if f==0:break
    cm+=1
'''print(cn,cm)'''
print(max(cn,cm))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    sumA = np.cumsum(A)
    sumB = np.cumsum(B)
    #print(sumA)
    #print(sumB)

    books = 0
    for i in range(len(sumA)):
        t = K-sumA[i]
        #print(t)
        if t<0:
            break
        idx = np.abs(np.asarray(sumB) - t).argmin()
        #print("A: {}, B: {}, books:{}".format(i+1, idx+1, (i+idx+2)))
        books = max(books, i+idx+2)
    
    print(books)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(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()))

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())
A =list(map(int,input().split()))
B =list(map(int,input().split()))

C =A+B
C.sort()

min = 0
cnt= 0

if sum(C) < K:
  print(len(C))
else:
  for i in range(len(C)):
    if min < K:
      cnt+=1
      min+=C[i]
    else:
      print(cnt-1)
      break

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(t) for t in input().split()]
A+=[10**10]
B+=[10**10]
cnt=0
ans=0
a=0
b=0
ans+=min(A[a],B[b])
while ans<=K:
    cnt+=1
    if A[a]<B[b]:
        a+=1
    elif A[a]==B[b]:
        a+=1
    elif A[a]>B[b]:
        b+=1
    ans+=min(A[a],B[b])
print(cnt)

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

    time = sum(A)
    for i in reversed(range(N)):
        if time <= K:
            i_A = i
            break
        time -= A[i]

    if time == 0:
        ans = 0
        for i in range(M):
            time += B[i]
            if time > K:
                break
            ans += 1
    else:
        ans = i_A + 1
        cnt = i_A + 1
        for i in range(M):
            time += B[i]
            cnt += 1
            if time > K:
                for j in reversed(range(i_A + 1)):
                    time -= A[i_A]
                    cnt -= 1
                    if time <= K:
                        break
                if time > K:
                    break
            else:
                if cnt > ans:
                    ans = cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    INF = 10**18
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.append(INF)
    b.append(INF)
    ap = 0
    bp = 0

    cnt = 0
    now = 0
    while now <= k:
        if a[ap] <= b[bp]:
            now += a[ap]
            ap += 1
        else:
            now += b[bp]
            bp += 1
        if now <= k:
            cnt += 1
        if ap + bp == n + m:
            break
    print(cnt)

main()