Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ai, bi = 0, 0
a.append(10**10)
b.append(10**10)
cnt = 0
tt = 0
while True:
    if a[ai] > b[bi]:
        if (tt + b[bi] > k):
            break
        cnt += 1
        tt += bi
        bi += 1
    else:
        if (tt + a[ai] > k):
            break
        cnt += 1
        tt += a[ai]
        ai += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_right, bisect_left

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

ap = [0 for i in range(n)]
bp = [0 for j in range(m)]

for i in range(n):
	if i == 0:
		ap[i] = a[i]
	else: 
		ap[i] = a[i] + ap[i - 1]

for i in range(m):
	if i == 0:
		bp[i] = b[i]
	else: 
		bp[i] = b[i] + bp[i - 1]

bestRes = 0

#print(bp)

def search(x):
	left = 0 
	right = m - 1
	while right - left > 1:
		mid = left + (right - left) // 2
		if bp[mid] == x:
			return mid

		if bp[mid] < x:
			right = mid - 1
		else:
			left = mid + 1


	if bp[right] <= x:
		return right
	elif bp[left] <= x:
		return left
	else:
		return left - 1

for i in range(n):
	#print(i)
	if ap[i] > k:
		break

	rest = k - ap[i]

	#print(rest)

	if bp[0] > rest:
		bestRes = max(bestRes, i)

	else:
		count = bisect_right(bp, rest)
		#print(i, rest, count)

		bestRes = max(bestRes, i + count + 1)


#print(bp)
#bisect_right(bp, k)

if k > bp[0]:
	count = bisect_right(bp, k)
	bestRes = max(bestRes, count)

print(bestRes)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = 0
j = 0
total = 0

ac = list(accumulate(a))
bc = list(accumulate(b))
ans = 0
for i in range(bisect.bisect(ac, k)):
    bi = bisect.bisect(bc, k - ac[i])
    ans = max(ans, i+1+bi)
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()))
r=0
t=0
m_i=0
n_i=0
m+=-1
n+=-1
for i in range(m+n+2):
  #print(n_i)
  a_i=a[min(n_i,n)]
  b_i=b[min(m_i,m)]
  if ((a_i>b_i and m_i <=m) or (a_i>b_i and n_i == n)):
    m_i+=1
    t+=b_i
    #m_i=min(m_i,m)
  else:
    n_i+=1
    t+=a_i
    #n_i=min(n_i,n)
  if t>k:
    break
  r+=1
print(r)

Submission status: Wrong Answer

Solution code:


N, M, K = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = 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.pop(0)
    else:
        selected_book = As.pop(0)

    total_time += selected_book

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

    if total_time > K:
        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 += [10**10]
B += [10**10]

ans = 0
T = 0
a, b = 0, 0
while True:
    if A[a] <= B[b]:
        T += A[a]
        a += 1
    else:
        T += B[b]
        b += 1
    if T > K:
        break
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
input = raw_input

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

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

cur = 0
a_cumsum = []
for i in range(n):
    cur += As[i]
    if cur > k:
        n = i
        break
    else:
        a_cumsum.append(cur)

cur = 0
b_cumsum = []
for i in range(m):
    cur += Bs[i]
    if cur > k:
        m = i
        break
    else:
        b_cumsum.append(cur)
#print("n", n)
#print("m", m)
#print(a_cumsum)
#print(b_cumsum)

out = 0
for i in range(n):
    a_count = i +1
    cur = a_cumsum[i]
    cur_count = None
    
    for j in reversed(range(m)):
        b_count = j + 1
        cur2 = cur + b_cumsum[j]
        if cur2 <= k:
            cur_count = a_count + b_count
            #print(i, a_count, b_count)
            break
    
    if cur_count is None:
        cur_count = a_count
        #print(i, a_count, 0)
    out = max(out, cur_count)

print(out)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque

readline = sys.stdin.buffer.readline

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

count = time = a = b = 0

while True:
    a = A[0] if len(A) else float('inf')
    b = B[0] if len(B) else float('inf')

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

    if a < b:
        time += a
        count += 1
        A.popleft()

    else:
        time += b
        count += 1
        B.popleft()

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()))
books = 0
cost = 0
for i in range(N+M):
    if cost > K:
        books -= 1
        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)
    
if books <= 0:
    print(0)
else:
    print(books)

Submission status: Wrong Answer

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    #rdivisors=[]
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################

def main():
    #code goes here
    n,m,k=mi()
    L=li()
    R=li()
    ptr1=0
    ptr2=0
    totaltime=0
    check=True
    arr=[]
    i = j  = 0
         
    while i < len(L) and j < len(R): 
        if L[i] < R[j]: 
            arr.append(L[i]) 
            i+= 1
        else: 
            arr.append(R[j]) 
            j+= 1
        
    # Checking if any element was left 
    while i < len(L): 
        arr.append(L[i]) 
        i+= 1
        
    while j < len(R): 
        arr.append(R[j]) 
        j+= 1
    s=0 
    for i in arr:
        if totaltime+i<=k:
            totaltime+=i
            s+=1
        else:
            break
    print(s)
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Wrong Answer

Solution code:
a,b,c=map(int,input().split())
li_a=list(map(int,input().split()))
li_b=list(map(int,input().split()))
for i in li_b:
  li_a.append(i)
li_a.sort()
count=0
while c>=0:

    if count==a+b:
      break
    c=c-li_a[count]
    if c<0:
      break
    count+=1
    
    
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, M, K = LI()
A = LI()
B = LI()
A.append(INF)
B.append(INF)

now = 0
a = 0
b = 0
ans = 0
while True:
    m = min(A[a], B[b])

    if now + m <= K:
        now += m
        ans += 1

        if m == A[a]:
            a += 1
        else:
            b += 1
        if a >= N and b >= M:
            break        
    else:
        break

print(ans)

Submission status: Wrong Answer

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

L = []
for i in range(N+M):
  if A[0] >= B[0]:
    L.append(B[0])
    B.pop(0)
  else:
    L.append(A[0])
    A.pop(0)

ans = 0
for i in range(N+M):
  ans += L[i]
  if ans > K:
    print(i)
    break
    
if ans <= K:
  print(N+M)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
it = 200001

k = 0
count = 0
select = list()
for i in range(it):
  print("i: " + str(i))
  if len(A) == 0 and len(B) == 0:
    break
  elif len(A) == 0:
    # Bの本のみ
    select = B
  elif len(B) == 0:
    # Aの本のみ
    select = A
  elif A[0] <= B[0]:
    # BよりもAの方が早く読める(同じも含む)
    select = A
  elif A[0] > B[0]:
    select = B
  k += select[0]
  if k <= K:
    count += 1
  else:
    break
  select.pop(0)
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-27 20:55:19 +0900
# LastModified: 2020-06-27 21:24:18 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import deque

def main():
    n, m, k = map(int, input().split())
    a = deque(list(map(int, input().split())))
    b = deque(list(map(int, input().split())))
    len_total = len(a)+len(b)
    cnt = 0
    have = 0
    while k > have:
        if not a and not b:
            print(len_total)
            return
        elif a and not b:
            have += a.popleft()
            if have > k:
                break
            cnt += 1
        elif b and not a:
            have += b.popleft()
            if have > k:
                break
            cnt += 1
        else:
            if a[0] < b[0]:
                have += a.popleft()
                if have > k:
                    break
                cnt += 1
            else:
                have += b.popleft()
                if have > k:
                    break
                cnt += 1
    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(" ")))

i, j = 0, 0
readed = 0
count = 0

while True:
    if i >= n:
        if j >= m:
            break
        else:
            readed += b[j]
            j += 1
    elif j >= m:
        readed += a[i]
        i += 1
    elif a[i] <= b[j]:
        readed += a[i]
        i += 1
    #elif a[i] == b[j]:

    else:
        readed += b[j]
        j += 1
    if readed > k:
        break
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

readline = sys.stdin.readline

n, m, k = map(int, readline().split())
a = deque(map(int, readline().split()))
b = deque(map(int, readline().split()))
for i in range(n+m+1):
    if not a and not b:
        print(i)
        sys.exit()
    elif not a:
        x = b.popleft()
        if k < x:
            print(i)
            sys.exit()
        else:
            k -= x
    elif not b:
        x = a.popleft()
        if k < x:
            print(i)
            sys.exit()
        else:
            k -= x
    elif a[0] < b[0]:
        x = a.popleft()
        if k < x:
            print(i)
            sys.exit()
        else:
            k -= x
    else:
        x = b.popleft()
        if k < x:
            print(i)
            sys.exit()
        else:
            k -= x
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()))
books = sorted(A + B)

ans = len(books)
for i, t in enumerate(books):
  if K < t:
    ans = i
    break
  K -= t
  
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
A = [int(x) for x in input().split()]+[10**10]
B = [int(y) for y in input().split()]+[10**10]
a = 0
b = 0
hon = 0

while K >= A[a] or K >= B[b]:
    if a < N and K >= A[a] and A[a] <= B[b]:
        K -= A[a]
        a += 1
        hon += 1
    if b < M and K >= B[b] and B[b] <= A[a]:
        K -= B[b]
        b += 1
        hon += 1
    if hon == N+M:
        break
print(hon)

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 = 0
b = 0
La = len(A)
Lb = len(B)
ans = 0
S = 0
while S <= K:
  if a == N and b == M:
    ans += 1
    break
  if a == N:
    va = 10000000000000
  else:
    va = A[a]
  if b == M:
    vb = 10000000000000
  else:
    vb = B[b]
    
  if a  < b:
    a += 1
    S  += va
    ans += 1
  else:
    b += 1
    S += vb
    ans += 1
 
  
print(ans-1)

Submission status: Wrong Answer

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

a_next_index = 0
b_next_index = 0
read_time = 0
readed_cnt = 0

while (a_next_index < n or b_next_index < m):
    if a_next_index == n:
        read_time += b[b_next_index]
        b_next_index += 1
    elif b_next_index == m:
        read_time += a[a_next_index]
        a_next_index += 1
    elif a[a_next_index] < b[b_next_index]:
        read_time += a[a_next_index]
        a_next_index += 1
    else:
        read_time += b[b_next_index]
        b_next_index += 1

    if (read_time > k):
        break

    readed_cnt += 1

print(readed_cnt)

Submission status: Wrong Answer

Solution code:
import sys
import collections

rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, m, k = rm()
a = collections.deque(rl())
b = collections.deque(rl())

time = 0
cnt = 0
while len(a) != 0 and len(b) != 0:
  if a[0] > b[0]:
    t = b.popleft()
  else:
    t = a.popleft()
  time += t
  if time <= k:
    cnt += 1
  else:
    break
else:
  if len(a) == 0:
    for t in b:
      time += t
      if time <= k:
        cnt += 1
      else:
        break
  elif len(b) == 0:
    for t in a:
      time += t
      if time <= k:
        cnt += 1
      else:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import math as mt
input=sys.stdin.buffer.readline  
t=1
#t=int(input())
for _ in range(t):
    #n=int(input())
    n,m,k=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    ans=0
    suma=0
    i,j=0,0
    while i<n and j<m and suma<=k:
        if l1[i]<l2[j]:
            if suma+l1[i]<=k:
                suma+=l1[i]
                ans+=1
            i+=1
            
        else:
            if suma+l2[j]<=k:
                suma+=l2[j]
                ans+=1
            j+=1
           
    if  j<m and suma<k:
        for i1 in range(j,m):
            if suma+l2[i1]<=k:
                suma+=l2[i1]
                ans+=1
    if  i<n and suma<k:
        for i1 in range(i,n):
            if suma+l1[i1]<=k:
                ans+=1
                suma+=l1[i1]
                
        
    print(ans)

Submission status: Wrong Answer

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

v = 0
ans = 0
for i in range(N):
    if v + A[i] <= K:
        v += A[i]
    else:
        mi = i-1
        break
else:
    mi = N-1

for j in range(M):
    while mi > -1 and v + B[j] > K:
        v -= A[mi]
        mi -= 1
    v += B[j]
    if v <= K:
        ans = max(ans, mi+1+ j+1)
        
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
m = int(data[0].split()[1])

k = int(data[0].split()[2])

a = [int(s) for s in data[1].split()]
b = [int(s) for s in data[2].split()]

counter = 0
time = 0
for i in range(1,n+m+1):
    if a != [] and b!= []:
        if time + a[0] > k and time + b[0] > k:
            break
        else:
            if a[0] >= b[0]:
                counter += 1
                time += b[0]
                b.pop(0)
            else:
                counter += 1
                time += a[0]
                a.pop(0)
    elif a == []:
        if time + b[0] > k:
            break
        else:
            counter += 1
            time += b[0]
            b.pop(0)
    elif b == []:
        if time + a[0] > k:
            break
        else:
            counter += 1
            time += a[0]
            a.pop(0)
print(counter)

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

Submission status: Wrong Answer

Solution code:
import atexit, io, sys 
  
buffer = io.BytesIO() 
sys.stdout = buffer
  
@atexit.register 
def write(): 
    sys.__stdout__.write(buffer.getvalue()) 

n,m,k = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
ptr1 = 0
ptr2 = 0
ans = 0
curr = 0
while ptr1 < n and ptr2 < m:
	if a[ptr1] < b[ptr2]:
		curr += a[ptr1]
		ptr1 += 1
	else:
		curr += b[ptr2]
		ptr2 += 1
	if curr > k:
		break
	ans += 1

while ptr1 < n:
	curr += a[ptr1]
	ptr1 += 1
	if curr > k:
		break
	ans += 1

while ptr2 < m:
	curr += b[ptr2]
	ptr2 += 1
	if curr > k:
		break
	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()))

total = 0
len_A = len(A)
len_B = len(B)
i = 0
j = 0
while True:
  a_i = A[i] if i < len_A else 1e10
  b_j = B[j] if j < len_B else 1e10
  if i >= len_A and j >= len_B:
    break
  if a_i < b_j:
    K -= a_i
    i += 1
  else:
    K -= b_j
    j += 1
  if K >= 0:
    total += 1
  else:
    break
    
print(total)

Submission status: Wrong Answer

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

a.reverse()
b.reverse()

total = 0
ans = 0
while True:

    yonda = 0
    if len(a) > 0  and len(b) > 0:
        yonda = a.pop() if a[-1] < b[-1] else b.pop()
    elif len(a) > 0:
        yonda = a.pop()
    elif  len(b) > 0:
        yonda = b.pop()
    else :
        break

    total += yonda
    if total  >= k :
        break
    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()))
i = 0
j = 0
time = 0
book = 0
flag = 0
while time <= k:
    if i < n and j < m:
        if a[i] < b[j]:
            time += a[i]
            i += 1
            book += 1
        else:
            time += b[j]
            j += 1
            book += 1
    elif i < n and j >= m:
        time += a[i] 
        i += 1
        book += 1
    elif i >= n and j < m:
        time += b[j]
        j += 1
        book += 1
    else:
        flag = 1
        break
if flag == 1:
    print(n+m)
else:
    print(book-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.append(10**9)
b.append(10**9)
# k分以内
ans=0
i=0
while True:
    ans+=min(a[0],b[0])
    if a[0]>b[0]:
        b.pop(0)
    else:
        a.pop(0)
        
    if ans>k:
        print(i)
        quit()
    i+=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
num = 0
while True:
  if time > K:
    break
  if len(A) == 0 and len(B) == 0:
    break
  elif len(A) == 0:
    if (K - time) < B[0]:
      break
    time += B[0]  
    num += 1
    del B[0]
  elif len(B) == 0:
    if (K - time) < A[0]:
      break
    num += 1
    time += A[0]
    del A[0]
  elif len(A) != 0 and len(B) != 0:
    if A[0] <= B[0]:
      if (K - time) < A[0]:
        break
      time += A[0]
      num += 1
      del A[0]
    else:
      if (K - time) < B[0]:
        break
      num += 1
      time += B[0]
      del B[0]
print(num)

Submission status: Wrong Answer

Solution code:
N,M,K = input().split()
N= int(N)
M=int(M)
K=int(K)
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
count = 0
ai = 0
bi = 0

while (time < K):
    if ai < N and bi < M:
        if A[ai] <= B[bi]:
            print(A[ai])
            time += A[ai]
            count += 1
            ai += 1
        else :
            print(B[bi])
            time += B[bi]
            count += 1
            bi += 1
    else:
        if ai == N and bi != M:
            print(B[bi])
            time += B[bi]
            count+=1
            bi+=1
        else:
            if ai != N and bi == M:
                print(A[ai])
                time += A[ai]
                count += 1
                ai += 1
            else :
                break

if time <= K:
    print(count)

else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
Af = False
Bf = False
count = 0

for _ in range(n+m):
  if Af and Bf:
    break
  if A[0] > k and B[0] > k:
    break
  if Af:
    k -= B.pop(0)
    count += 1
    continue
  if Bf:
    k -= A.pop(0)
    count += 1
    continue
  if A[0] < B[0]:
    k -= A.pop(0)
    count += 1
  else:
    k -= B.pop(0)
    count += 1
  if len(A)==0:
    A.append((10**9)+1)
    Af = True
  if len(B)==0:
    B.append((10**9)+1)
    Bf = True
print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque, defaultdict, Counter
N, M, K = (int(i) for i in input().split())  
A = list(map(int, input().split()))
B = list(map(int, input().split()))
da = deque(A)
db = deque(B)

ans = 0
total = 0
while True:
  if len(da) > 0 and len(db) > 0:
    if da[0] >= db[0]:
      total += db.popleft()
    else:
      total += da.popleft()
  elif len(db) > 0:
    total += db.popleft()
  elif len(da) > 0:
    total += da.popleft()
  else:
    break

  if total >= K:
    if total == K:
      ans += 1
    print(ans)
    exit()
  else:
    ans += 1

print(N+M)