Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
from collections import deque

if __name__ == '__main__':
	n,m,k = map(int,input().split())
	d1 = deque(map(int,input().split()))
	d2 = deque(map(int,input().split()))

	total = 0
	cnt = 0

	while True:
		lend1 = len(d1)
		lend2 = len(d2)
		if lend1 == 0 and lend2 == 0:
			break

		if lend1 != 0 and lend2 != 0:
			if d1[0] < d2[0]:
				total += d1.popleft()
			else:
				total += d2.popleft()
		else:
			if lend1 != 0:
				total += d1.popleft()
			else:
				total += d2.popleft()
		if k < total :
			break
		cnt += 1

	print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()][::-1]
b=[int(i) for i in input().split()][::-1]
ans=chk=0
while 1:
    if a[-1]<=b[-1] and a[-1]<=k:
        k-=a[-1]
        a.pop()
        ans+=1
    elif a[-1]>b[-1] and b[-1]<=k:
        k-=b[-1]
        b.pop()
        ans+=1
    else:
        break
    if len(a)==0: a.append(k+1)
    if len(b)==0: b.append(k+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()))
ans = 0

while k > 0:
    if n != 0 and m != 0:
        if a[0] < b[0]:
            min = a.pop(0)
            n -= 1    
        else:
            min = b.pop(0)
            m -= 1
    elif n != 0:
        min = a.pop(0)
        n -= 1
    elif m != 0:
        min = b.pop(0)
        m -= 1

    if k >= min:
        ans += 1
        k -= min
    else:
        break

    if n == 0 and m == 0:
        break

print(ans)

Submission status: Wrong Answer

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

while k > 0 and n > 0 or m > 0:
    if a[0] < b[0]:
        min = a.pop(0)
        n -= 1    
    else:
        min = b.pop(0)
        m -= 1
    
    if n == 0:
        a.append(10**9)
    if m == 0:
        b.append(10**9)

    if k >= min:
        ans += 1
        k -= min
    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()))
c = a + b
c.sort()
count = 0
t = 0
for i in range(len(c)):
  t += c[i]
  if t > K:
    print(i)
    exit()
print(len(c))

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


def cusum(array):
    for i in range(len(array) - 1):
        array[i + 1] += array[i]


cusum(A)
cusum(B)
tsundoku = 0
time = 0
ia = 0
ib = 0

for ia, x in enumerate(A):
    if x > K:
        break
    for ib, y in enumerate(B):
        if (x + y) > K:
            break
        if (ia + ib) > tsundoku - 2:
            tsundoku = ia + ib + 2

print(tsundoku)

Submission status: Wrong Answer

Solution code:
from collections import deque

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


def cusum(array):
    for i in range(len(array) - 1):
        array[i + 1] += array[i]


cusum(A)
cusum(B)
A.appendleft(0)
B.appendleft(0)
tsundoku = 0
time = 0

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

    time = A[0] + B[0]
    if K >= time:
        tsundoku += 1

print(tsundoku)

Submission status: Wrong Answer

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


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    cnt = 0
    total_time = 0

    i_a = 0
    i_b = 0
    for i in range(N+M):
        if A[i_a] < B[i_b]:
            total_time += A[i_a]
            i_a += 1
        else:
            total_time += B[i_b]
            i_b += 1

        if total_time > K:
            break
        cnt += 1

        if i_a == N:
            for b in B[i_b:]:
                total_time += b
                if total_time > K:
                    break
                cnt += 1
            break

        if i_b == M:
            for a in A[i_a:]:
                total_time += a
                if total_time > K:
                    break
                cnt += 1
            break


    return cnt


# 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]"
    print(solve(N, M, K, A, B))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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


def cusum(array):
    for i in range(len(array) - 1):
        array[i + 1] += array[i]


cusum(A)
cusum(B)
A.appendleft(0)
B.appendleft(0)
tsundoku = 0
time = 0

while K > time:
    if len(A) > 1 and len(B) > 1:
        if A[0] < B[0]:
            A.popleft()
        else:
            B.popleft()
    elif len(A) > 1 and len(B) == 1:
        A.popleft()
    else:
        B.popleft()

    time = A[0] + B[0]
    if K >= time:
        tsundoku += 1

print(tsundoku)

Submission status: Wrong Answer

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


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    cnt = 0
    total_time = 0

    i_a = 0
    i_b = 0
    for i in range(N+M):
        if A[i_a] < B[i_b]:
            total_time += A[i_a]
            i_a += 1
        else:
            total_time += B[i_b]
            i_b += 1

        if total_time > K:
            break
        cnt += 1

        if i_a == N:
            for b in B[i_b:]:
                total_time += b
                if total_time > K:
                    break
                i_b += 1
                cnt += 1
            break

        if i_b == M:
            for a in A[i_a:]:
                total_time += a
                if total_time > K:
                    break
                i_a += 1
                cnt += 1
            break


    return cnt


# 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]"
    print(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()))
max_value = max(max(a),max(b)) + 1
ans,count = 0,0
a_counter,b_counter = 0,0
a_value,b_value = 0,0
for i in range(n + m):
    if a_counter < n:
        a_value = a[a_counter]
    else:
        a_value = max_value
    if b_counter < m:
        b_value = b[b_counter]
    else:
        b_value = max_value
    
    if a_value <= b_value:
        count += a_value
        a_counter += 1
    else:
        count += b_value
        b_counter += 1
    
    if k < count:
        break
    else:
        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()))
max_value = max(max(a),max(b)) + 1
ans,count = 0,0
a_counter,b_counter = 0,0
a_value,b_value = 0,0
for i in range(n + m):
    if a_counter < n:
        a_value = a[a_counter]
    else:
        a_value = max_value
    if b_counter < m:
        b_value = b[b_counter]
    else:
        b_value = max_value
    
    if a_value < b_value:
        count += a_value
        a_counter += 1
    elif b_value < a_value:
        count += b_value
        b_counter += 1
    else:
        count += a_value
        a_counter += 1
    if k < count:
        break
    else:
        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()))
max_value = max(max(a),max(b)) + 1
ans,count = 0,0
a_counter,b_counter = 0,0
a_value,b_value = 0,0
for i in range(n + m):
    if a_counter < n:
        a_value = a[a_counter]
    else:
        a_value = max_value
    if b_counter < m:
        b_value = b[b_counter]
    else:
        b_value = max_value
    
    if a_value < b_value:
        count += a_value
        a_counter += 1
    elif b_value < a_value:
        count += b_value
        b_counter += 1
    else:
        count += a_value
        a_counter += 1
    if k <= count:
        break
    else:
        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()))
max_value = max(max(a),max(b)) + 1
ans,count = 0,0
a_counter,b_counter = 0,0
a_value,b_value = 0,0
for i in range(n + m):
    if a_counter < n:
        a_value = a[a_counter]
    else:
        a_value = max_value
    if b_counter < m:
        b_value = b[b_counter]
    else:
        b_value = max_value
    if a_value < b_value:
        count += a_value
        a_counter += 1
    elif b_value < a_value:
        count += b_value
        b_counter += 1
    elif (a_value == b_value) and (a_counter <= b_counter):
        count += a_value
        a_counter += 1
    elif (a_value == b_value) and (b_counter < a_counter):
        count += b_value
        b_counter += 1
    else:
        break
    if k < count:
        break
    else:
        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()))
ans,count = 0,0
a_counter,b_counter = 0,0
a_value,b_value = 0,0
for i in range(n + m):
    if a_counter < n:
        a_value = a[a_counter]
    if b_counter < m:
        b_value = b[b_counter]
    if a_value < b_value:
        count += a_value
        a_counter += 1
    elif b_value < a_value:
        count += b_value
        b_counter += 1
    elif (a_value == b_value) and (a_counter <= b_counter):
        count += a_value
        a_counter += 1
    elif (a_value == b_value) and (b_counter < a_counter):
        count += b_value
        b_counter += 1
    else:
        break
    if k < count:
        break
    else:
        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()))
a_counter = 0
b_counter = 0
a_index = 1
b_index = 1
ans = 0
for i in range(n+m):
    if a_counter >= n:
        a_value = 0 
    else:
        a_value = a[a_counter]
    if b_counter >= m:
        b_value = 0
    else:
        b_value = b[b_counter]
    
    if a_value < b_value and not (a_value == 0):
        k -= a_value
        a_counter += 1
    elif a_value > b_value and not (b_value == 0):
        k -= b_value
        b_counter += 1
    elif a_value == b_value and not (a_value == 0):
        k -= a_value
        a_counter += 1
    if k <= 0:
        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()))
a_counter = 0
b_counter = 0
a_index = 1
b_index = 1
ans = 0
for i in range(n+m):
    if a_counter >= n:
        a_value = 0 
    else:
        a_value = a[a_counter]
    if b_counter >= m:
        b_value = 0
    else:
        b_value = b[b_counter]
    
    if a_value < b_value and not (a_value == 0):
        k -= a_value
        a_counter += 1
    elif a_value >= b_value and not (b_value == 0):
        k -= b_value
        b_counter += 1
    print(k)
    if k <= 0:
        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()))
a_counter = 0
b_counter = 0
a_index = 1
b_index = 1
ans = 0
for i in range(n+m):
    if a_counter >= n:
        a_value = 0 
    else:
        a_value = a[a_counter]
    if b_counter >= m:
        b_value = 0
    else:
        b_value = b[b_counter]
    
    if a_value < b_value and not (a_value == 0):
        k -= a_value
        a_counter += 1
    elif a_value > b_value and not (b_value == 0):
        k -= b_value
        b_counter += 1
    if k <= 0:
        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()))
a_counter = 0
b_counter = 0
a_index = 1
b_index = 1
ans = 0
for i in range(n+m):
    if a_counter >= n:
        a_value = 0 
    else:
        a_value = a[a_counter]
    if b_counter >= m:
        b_value = 0
    else:
        b_value = b[b_counter]
    
    if a_value < b_value and not (a_value == 0):
        k -= a_value
        a_counter += 1
    elif a_value > b_value and not (b_value == 0):
        k -= b_value
        b_counter += 1
    if k < 0:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

def main():
    n, m, k = map(int, input().split())
    a = collections.deque(list(map(int, input().split())))
    b = collections.deque(list(map(int, input().split())))
    ans = solve(n, m, k, a, b)
    print(ans)

def solve(n, m, k, a, b):
    ans = 0
    tmp = 0
    while tmp <= k:
        if len(a) < 1 and len(b) < 1:
            break
        elif len(a) < 1:
            tmp += b.popleft()
        elif len(b) < 1:
            tmp += a.popleft()
        elif a[0] < b[0]:
            tmp += a.popleft()
        else:
            tmp += b.popleft()
        if tmp <= k:
            ans += 1
    return ans

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))
SA = list(accumulate(A))
SB = list(accumulate(B))

ans = 0
for i in range(len(SA)):
    if tmp := K-SA[i] < 0:
        break
    ans = max(ans, bisect_right(SB, tmp)+i)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))
SA = list(accumulate(A))
SB = list(accumulate(B))

ans = 0
for i in range(len(SA)):
    if tmp := K-SA[i] < 0:
        break
    ans = max(ans, bisect_right(SB, tmp))
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))
SA = list(accumulate(A))
SB = list(accumulate(B))

ans = 0
for i in range(len(SA)):
    ans = max(ans, bisect_right(SB, K-SA[i]))
print(ans)

Submission status: Wrong Answer

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

from collections import deque

d_A = deque(A)
d_B = deque(B)

ans = -1
read_time_sum = 0
while read_time_sum <= K:
    if not d_A and not d_B:
        break
    if not d_A :
        read_time_sum += d_B.popleft()
        continue
    if not d_B:
        read_time_sum += d_A.popleft()
        continue
    if d_A[0] >= d_B[0]:
        read_time_sum += d_B.popleft()
    else:
        read_time_sum += d_A.popleft()

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

from collections import deque

d_A = deque(A)
d_B = deque(B)

ans = -1
read_time_sum = 0
while read_time_sum <= K:
    ans += 1
    if not d_A and not d_B:
        break
    if not d_A:
        read_time_sum += d_B.popleft()
        continue
    if not d_B:
        read_time_sum += d_A.popleft()
        continue
    if d_A[0] >= d_B[0]:
        read_time_sum += d_B.popleft()
    else:
        read_time_sum += d_A.popleft()
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            break
        else:
            count += 1
            K -= A[i_a]
    # replace B item
    while True:
        if i_b >= len(B):
            break
        if K < B[i_b] :
            break
        else :
            K -= B[i_b]
            count += 1
            i_b += 1
    for i in range((i_a-1),-1,-1):
        K += A[i]
        while True:
            if i_b >= len(B):
                break
            if K < B[i_b] :
                break
            else :
                K -= B[i_b]
                i_b += 1
        count = max(count,((i+1)+(i_b)))
    print(count)

Submission status: Wrong Answer

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

count = 0
time = 0
while a_list or b_list:
    if not a_list:
        time += b_list.pop(0)
    elif not b_list:
        time += a_list.pop(0)
    else:
        if a_list[0] < b_list[0]:
            time += a_list.pop(0)
        else:
            time += b_list.pop(0)
    if time > K:
        break
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = input().split()
n = int(n)
m = int(m)
k = int(k)

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
nmax = n+m
imax = n
for i in range(n):
  #print(a[:i+1], sum(a[:i+1]), i+1)
  if sum(a[:i+1]) > k:
    imax = i
    break

for i in range(imax, -1, -1):
  for j in range(1, m+1):
    #print(sum(a[:i]+b[:j]), a[:i]+b[:j])
    if sum(a[:i]+b[:j]) > k:
      #print(sum(a[:i]+b[:j]), a[:i]+b[:j])
      nmax = i+j
      break
print(nmax)

Submission status: Wrong Answer

Solution code:
import itertools


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

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

p = range(1,n+m+1)
#print(list(p))
nmax = 0
for i in p:
  flag = False
  for j in range(i+1):
    x = j
    y = i-j
    sum_ = sum(a[:j]+b[:i-j])
    if sum_ <= k:
      flag = True
      nmax = i
      #print(sum_, i)
  if not flag:
    break
print(nmax)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

def or_less(array, x):
    # arrayの中のx以下のものの個数
    # arrayの中のx以下のもののうちの最大値
    index = bisect_right(array, x)
    if index == 0:
        or_less_int = -float('inf')
    else:
        or_less_int = array[index - 1]
    return [index, or_less_int]

N, M, K = getNM()
A = getList()
A.append(0)
A.sort()
B = getList()
B.sort()

A_imos = copy.deepcopy(A)
for i in range(N):
    A_imos[i + 1] += A_imos[i]

B_imos = copy.deepcopy(B)
for i in range(M - 1):
    B_imos[i + 1] += B_imos[i]

ans = 0
for i in range(N + 1):
    if A_imos[i] > K:
        continue
    index = or_less(B_imos, K - A_imos[i])[0]
    ans = max(ans, i + index)
print(ans)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

def or_less(array, x):
    # arrayの中のx以下のものの個数
    # arrayの中のx以下のもののうちの最大値
    index = bisect_right(array, x)
    if index == 0:
        or_less_int = -float('inf')
    else:
        or_less_int = array[index - 1]
    return [index, or_less_int]

N, M, K = getNM()
A = getList()
A.append(0)
A.sort()
B = getList()
B.append(0)
B.sort()

A_imos = copy.deepcopy(A)
for i in range(N):
    A_imos[i + 1] += A_imos[i]

B_imos = copy.deepcopy(B)
for i in range(M):
    B_imos[i + 1] += B_imos[i]

ans = 0
for i in range(N + 1):
    if A_imos[i] > K:
        continue
    index = or_less(B_imos, K - A_imos[i])[0]
    ans = max(ans, i + index - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

def or_less(array, x):
    # arrayの中のx以下のものの個数
    # arrayの中のx以下のもののうちの最大値
    index = bisect_right(array, x)
    if index == 0:
        or_less_int = -float('inf')
    else:
        or_less_int = array[index - 1]
    return [index, or_less_int]

N, M, K = getNM()
A = getList()
B = getList()

A_imos = copy.deepcopy(A)
for i in range(N - 1):
    A_imos[i + 1] += A_imos[i]

B_imos = copy.deepcopy(B)
for i in range(M - 1):
    B_imos[i + 1] += B_imos[i]

ans = 0
for i in range(N):
    if A_imos[i] > K:
        continue
    index = or_less(B_imos, K - A_imos[i])[0]
    ans = max(ans, (i + 1) + index)
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_a = [0]
s_b = [0]
for i in range(n):
    s_a.append(s_a[i] + a[i])
for i in range(m):
    s_b.append(s_b[i] + b[i])

ans = 0
ok = m
for i in range(n+1):
    for j in range(ok+1)[::-1]:
        if s_a[i] + s_b[j] <= k:
            ans = max(ans, i+j)
            tmp = j
    ok = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(400000)
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()])
desk_b = deque([int(n) for n in input().split()])

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()])
desk_b = deque([int(n) for n in input().split()])

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        # book_a = desk_a.popleft()
        # count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
        count_a = count
    else:
        count_a = count
    if len(desk_b) != 0:
        # book_b = desk_b.popleft()
        # count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
        count_b = count
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    return count - 1
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        # count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
        count_a = 0
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
        count_a = 0
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

# def max_n_book(desk_a, desk_b, count=0, k=K):
#     if k < 0:
#         return count - 1
#     if len(desk_a) != 0:
#         # book_a = desk_a.popleft()
#         # count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
#         count_a = 0
#     else:
#         count_a = count
#     if len(desk_b) != 0:
#         # book_b = desk_b.popleft()
#         # count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
#         count_a = 0
#     else:
#         count_b = count
#     return max(count_a, count_b)

# n_book = max_n_book(desk_a, desk_b, count=0, k=K)
n_book = 1
print(n_book)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()])
desk_b = deque([int(n) for n in input().split()])

print(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()))
ans = 0

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

while True:
    if min(a[0], b[0]) > 10 ** 9 or min(a[0], b[0]) > k:
        break
    
    if a[0] <= b[0]:
        k -= a.pop(0)
        ans += 1
    else:
        k -= b.pop(0)
        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()))
ans = 0

while True:
    a_ = a[0] if len(a) else 10 ** 9 + 1
    b_ = b[0] if len(b) else 10 ** 9 + 1
    
    if min(a_, b_) > 10**9 or min(a_, b_) > k:
        break
    
    if a_ <= b_:
        k -= a.pop(0)
        ans += 1
    else:
        k -= b.pop(0)
        ans += 1
print(ans)