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:
def resolve():
    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)
    min = 0
    ans = 0
    while True:
        if len(a) == 0 and len(b)==0:
            break
        elif len(a) == 0:
            bb = b.popleft()
            read = bb
            if min + read <= k:
                min += read
                ans += 1
            else:
                break
        elif len(b) == 0:
            ab = a.popleft()
            read = ab
            if min + read <= k:
                min += read
                ans += 1
            else:
                break

        else:
            ab = a.popleft()
            bb = b.popleft()
            if ab <= bb:
                b.appendleft(bb)
                read = ab
            else:
                a.appendleft(ab)
                read = bb
            if min + read <= k:
                min += read
                ans += 1
            else:
                break

    print(ans)
resolve()

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)
a = 0
b = 0
ans = 0
t = 0
while t < K :
    if A[a] < B[b]:
        if t+A[a] <= K:
            ans += 1
            t += A[a]
            a += 1
        else:
            break
    else:
        if t+B[b] <= K:
            ans += 1
            t += B[b]
            b += 1
        else:
            break
ans2 = 0
a = 0
b = 0
t = 0
while t < K :
    if A[a] > B[b]:
        if t+A[a] <= K:
            ans2 += 1
            t += A[a]
            a += 1
        else:
            break
    else:
        if t+B[b] <= K:
            ans2 += 1
            t += B[b]
            b += 1
        else:
            break
print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

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

    if time == K:
        print(ans)
    else:
        print(ans - 1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())
a = input().split()
b = input().split()
ad = deque()
bd = deque()
for i in range(n):
	ad.append(int(a[i]))
for i in range(m):
	bd.append(int(b[i]))
t = 0
f = 0
c = 0
while f == 0:
	aa = 1000000001
	bb = 1000000001
	if len(ad) != 0:
		aa = ad.popleft()
	if len(bd) != 0:
		bb = bd.popleft()
	if aa < bb:
		if t + aa > k:
			f = 1
		else:
			t += aa
			bd.appendleft(bb)
			c += 1
	else:
		if t + bb > k:
			f = 1
		else:
			t += bb
			ad.appendleft(aa)
			c += 1
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()]
count = 0
i = 0
j = 0
time = 0
flag = 0
while(time<=k and flag==0):
    flag = 1
    if(i<n and j<m):
        if(a[i]<=b[j] and (time+a[i]<=k)):
            count+=1
            time+=a[i]
            i+=1
            flag = 0
        elif(b[j]<=a[i] and (time+b[j]<=k)):
            count+=1
            time+=b[j]
            j+=1
            flag = 0
    elif(j<m and (time+b[j]<=k)):
        count+=1
        time+=b[j]
        j+=1
        flag = 0
    elif(i<n and (time+a[i]<=k)):
        count+=1
        time+=a[i]
        i+=1
        flag = 0
        

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

time = 0
count = 0
for _ in range(n + m):
    if len(a) > 0and len(b)>0:
        if a[-1] < b[-1]:
            time += a[-1]
            a = a[:-1]
        else:
            time += b[-1]
            b = b[:-1]
    elif len(a) == 0 and len(b) > 0:
        time += b[-1]
        b = b[:-1]
    elif len(b) == 0 and len(a) > 0:
        time += a[-1]
        a = a[:-1]
    if time > k:
        break
    else:
        count += 1
        
        
print(count)

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

        else:
            break
    else:
        if k>=b[j]:
            k-=b[j]
            #rint(k, b[j])
            cnt +=1
            j+=1
        else:
            break

while k>=0 and i<n:
    if k >= a[i]:
        k -= a[i]
        i+=1
        #print(k, a[i])
        cnt += 1
    else:
        break

while k>=0 and j<m:
    if k >= b[j]:
        k -= b[j]
        #print(k, b[j])
        cnt += 1
        j += 1
    else:
        #print(k,b[j])
        break
print(cnt)

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 = 0
j = 0
cnt = 0
while (i < n or j < m):
	val = 0
	if j == m:
		val = a[i]
		i += 1
	elif i == n:
		val = b[j]
		j += 1
	else:
		val = min(a[i], b[j])
		if val == a[i]:
			i += 1
		else:
			j += 1
	# print(val)
	if val <= k:
		cnt += 1
		k -= val
	else:
		break
print(cnt)

Submission status: Wrong Answer

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


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

sum_time = 0
count = 0
while True:
    if len(A) == 0 and len(B) == 0:
        break
    if len(A) == 0:
        now_read = B[0]
        B.pop(0)
    elif len(B) == 0:
        now_read = A[0]
        A.pop(0)
    elif A[0] < B[0]:
        now_read = A[0]
        A.pop(0)
    else:
        now_read = B[0]
        B.pop(0)
    if K < sum_time + now_read:
        break
    sum_time += now_read
    count += 1
print(count)

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]
cou = 0
while k>0:
  if len(a)==0 and len(b)==0:
    print(n+m)
    exit()
  if len(a)==0:
    while k>0 and len(b)!=0:
      if k>=b[-1]:
        k -= b[-1]
        b.pop()
        cou += 1
    print(cou)
    exit()
    
  if len(b)==0:
    while k>0 and len(a)!=0:
      if k>=a[-1]:
        k -= a[-1]
        a.pop()
        cou += 1
    print(cou)
    exit()
    
        
  if k<a[-1] and k<b[-1]:
    break
  if a[-1]<=b[-1]:
    if k-a[-1]>=0:
      k -= a[-1]
      a.pop()
      cou += 1
    else:
      break
  else:
    if k-b[-1]>=0:
      k -= b[-1]
      b.pop()
      cou += 1
    else:
      break
print(cou)

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

print(c)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def main():
    N, M, K = mi()
    A = list(mi())
    B = list(mi())

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


if __name__ == '__main__':
    main()

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.extend(b)
a.sort()
count = 0
for e in a:
  k -= e
  if k < 0:
    break
  count += 1
print(count)

Submission status: Wrong Answer

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

ans = 0

while k > 0:
  if a < n and b < m:
    if As[a] < Bs[b]:
      minimum = As[a]
      a += 1
    elif As[a] > Bs[b]:
      minimum = Bs[b]
      b += 1
    else:
      i = 1
      while a+i < n and b+i < m:
        if As[a+i] < Bs[b+i]:
          minimum = As[a]
          a += 1
          break
        elif As[a+i] > Bs[b+i]:
          minimum = Bs[b]
          b += 1
        else:
          i += 1
      else:
        if a+i < n:
          minimum = As[a]
          a += 1
        elif b+i < m:
          minimum = Bs[b]
          b += 1
        else:
          minimum = As[a]
          a += 1
  elif a < n:
    minimum = As[a]
    a += 1
  elif b < m:
    minimum = Bs[b]
    b += 1
  else:
    break
  
  if minimum > k:
    break
  
  k -= minimum
  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()))

p=0
q=[0,0]
while p<=k:
    if (q[0]<=n-1 and q[1]<=m-1):
        if a[q[0]]<b[q[1]]:
            p+=a[q[0]]
            if p>k:
                break
            q[0]+=1
        else:
            p+=b[q[1]]
            if p>k:
                break
            q[1]+=1
    elif (q[0]<=n-1 and q[1]>m-1):
        p+=a[q[0]]
        if p>k:
            break
        q[0]+=1
    elif (q[0]>n-1 and q[1]<=m-1):
        p+=b[q[1]]
        if p>k:
            break
        q[1]+=1
    else:
        break
print(q[0]+q[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 = K
A_count = 0
B_count = 0
ans = 0

for i in range(200001):
    if A_count >= N or B_count >= M:
        break
    if A[A_count] < B[B_count]:
        time -= A[A_count]
        if time < 0:
            break
        A_count += 1
        ans += 1
    elif A[A_count] >= B[B_count]:
        time -= B[B_count]
        if time < 0:
            break
        B_count += 1
        ans += 1

while time >= 0:
    if A_count >= N and B_count >= M:
        break
    if A_count < N:
        time -= A[A_count]
        if time < 0:
            break
        ans += 1
        A_count += 1
    if B_count < M:
        time -= B[B_count]
        if time < 0:
            break
        ans += 1
        B_count += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    N, M, K = mulinputs()
    an = list(map(int, input().split()))
    bm = list(map(int, input().split()))

    i, j, la, lb, t = 0, 0, len(an), len(bm), 0
    l = max(la, lb)
    while True:
        if i < la and j < lb:
            a, b = an[i], bm[j]
        elif i < la:
            a, b = an[i], INF
        elif j < lb:
            a, b = INF, bm[j]
        else:
            break
        c = 0
        if a <= b:
            c = a
            i += 1
        else:
            c = b
            j += 1
        if t + c <= K:
            t += c
            cnt += 1
        else:
            break

    # 出力
    print(cnt)

Submission status: Wrong Answer

Solution code:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

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

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

a_l = len(a)
b_l = len(b)

time = 0
count = 0
while True:
    if a == [] and b == []:
        break
    if a == []:
        temp = b.pop(0)
    elif b == []:
        temp = a.pop(0)
    elif a[0] < b[0]:
        temp = a.pop(0)
    else:
        temp = b.pop(0)
    time += temp
    if k < time:
        break
    else:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = a+b
c.sort()
i = 0
ans = 0
count = 0
if sum(c) <= k:
    print(n+m)
    exit()
if c[0] > k:
    print(0)
    exit() 

while True:
    ans += c[i]
    i += 1
    if ans > k:
        print(count)
        break
    count += 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.sort()
B.sort()
c = 0
ans = 0
ia = 0
ib = 0
while c <= K:
  if ia == N and ib == M:
    break
  elif ia == N:
    c += B[ib]
    if c <= K:
      ib += 1
      ans += 1
  elif ib == M:
    c += A[ia]
    if c <= K:
      ia += 1
      ans += 1
    
  elif A[ia] <= B[ib]:
    c += A[ia]
    if c <= K:
      ia += 1
      ans += 1
  else:
    c += B[ib]
    if c <= K:
      ib += 1
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, M, K = Scanner.map_int()
    A = Scanner.map_int()
    B = Scanner.map_int()
    time = 0
    ans = 0
    for a in A:
        if time + a > K:
            break
        time += a
        ans += 1
    x = ans
    j = 0
    while time <= K and j < M:
        if time + B[j] > K:
            break
        time += B[j]
        j += 1
        ans += 1
    tmp = ans
    for i in range(x):
        time -= A[i]
        tmp -= 1
        while time <= K and j < M:
            if time + B[j] > K:
                break
            time += B[j]
            j += 1
            tmp += 1
        ans = max(ans, tmp)
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

t = 0
ret = 0
while True:

    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        t += B.pop(0)
    elif len(B) == 0:
        t += A.pop(0)
    elif A[0] > B[0]:
        t += B.pop(0)
    else:
        t += A.pop(0)

    ret += 1
    if t > K:
        ret -= 1
        break

print(ret)

Submission status: Wrong Answer

Solution code:
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip("\n") for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst): print(*lst)
def OutV(lst): print(*lst, sep="\n")
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N, M, K = iInM()
A = iInLH()
B = iInLH()

id_a = -1
t_pre = 0
for i in range(N):
    if t_pre + A[i] <= K: ## read
        id_a += 1
        t_pre += A[i]

id_b = -1
for j in range(M):
    if t_pre + B[j] <= K: ## read
        id_b += 1
        t_pre += B[j]

ans = (id_a + 1) + (id_b + 1)
if id_a < 0:
    print(ans)
    exit()

while (id_a >= 0):
    t_pre -= A[id_a]
    id_a -= 1
    for j in range(id_b+1, M):
        if t_pre + B[j] <= K:
            id_b += 1
            t_pre += B[j]
    if ans < (id_a + 1) + (id_b + 1):
        ans = (id_a + 1) + (id_b + 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()))

a.reverse()
b.reverse()

ans = 0
cnt = 0
while ans < k:
    check = ans
    ap = 10000000000
    bp = 10000000000
    if a:
        ap = a.pop()
    if b:
        bp = b.pop()
    ans += min(ap, bp)
    cnt += 1
    if ap > bp:
        a.append(ap)
    else:
        b.append(bp)
    if ans > k:
        ans = check
        cnt -= 1
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

NMK=input().split(" ")
N=int(NMK[0])
M=int(NMK[1])
K=int(NMK[2])

A=np.array(input().split(" "),dtype=np.int64)
B=np.array(input().split(" "),dtype=np.int64)

time=0
A_idx=0
B_idx=0
cnt=0
while(True):
    if(A_idx<len(A) and B_idx<len(B)):
        if(A[A_idx]<B[B_idx]):
            time+=A[A_idx]
            A_idx+=1
        else:
            time+=B[B_idx]
            B_idx+=1
    elif(A_idx>=len(A) and B_idx<len(B)):
        time+=B[B_idx]
        B_idx+=1
    elif(B_idx>=len(B) and A_idx<len(A)):
        time+=A[A_idx]
        A_idx+=1
    else:
        break
    if(time>K):
        break
    else:
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(4100000)

def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = deque(A)
    D = deque(B)
    ans = 0
    pre_A = 0
    pre_B = 0
    flag_A = False
    flag_B = False
    cnt = 0
    while C or D:
        if not flag_A:
            if C:
                pre_A = C.popleft()
            else:
                pre_A = float('inf')
        if not flag_B:
            if D:
                pre_B = D.popleft()
            else:
                pre_B = float('inf')
        
        if pre_A >= pre_B:
            if ans + pre_B > K:
                break
            ans += pre_B
            cnt += 1
            flag_A = True
            flag_B = False
        else:
            if ans + pre_A > K:
                break
            ans += pre_A
            cnt += 1
            flag_B = True
            flag_A = False


    print(cnt)





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
import itertools
x = list(itertools.accumulate(a))
y = list(itertools.accumulate(b))

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

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    N, M, K = map(int, input().split())
    ns = deque()
    ms = deque()
    n_list = list(map(int, input().split()))
    m_list = list(map(int, input().split()))
    for n in n_list:
        ns.append(n)
    for m in m_list:
        ms.append(m)
    
    num_book = 0
    time = K
    while len(ns) > 0 or len(ms) > 0:
        if len(ns) > 0 and len(ms) > 0:
            if ns[-1] < ms[-1]:
                t = ns.popleft()
                if time >= t:
                    num_book += 1
                    time -= t
            else:
                t = ms.popleft()
                if time >= t:
                    num_book += 1
                    time -= t
        elif len(ns) > 0:
            t = ns.popleft()
            if time >= t:
                num_book += 1
                time -= t
        
        else:
            t = ms.popleft()
            if time >= t:
                num_book += 1
                time -= t

    print(num_book)

  
if __name__ == '__main__':
    main()

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()))
    sum = 0
    ai, bi = 0, 0
    for _ in range(200000):
        if a[0] <= b[0] and ai < len(a):
            k -= a[ai]
            ai += 1
        elif bi < len(b):
            k -= b[bi]
            bi += 1
        else:
            break
        if k < 0:
            break
        sum += 1
    print(sum)

if __name__ == "__main__":
    main()