Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.insert(0,0)
cntB=0
cnt_list=[]

for i in range(n+1):
  time=0
  for s in range(i+1):
    time+=A[s]
    cntA=s
  if time>k:
    break
  for j in range(m):
    if time+B[j]<=k:
      time+=B[j]
      cntB=j+1
    else:
      break
  cnt=cntA+cntB
  cnt_list.append(cnt)
  
print(max(cnt_list))

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cnt=0
time=0
s=0
t=0
flagA=False
flagB=False

while time<k and ( (time+A[s])<=k or (time+B[t])<=k ):
  if flagA==False and flagB==False:
    if A[s]<=B[t]:
      time+=A[s]
      s+=1
      if s==n:
        flagA=True
        A.append(10**10)
      cnt+=1
    elif A[s]>B[t]:
      time+=B[t]
      t+=1
      if t==m:
        flagB=True
        B.append(10**10)
      cnt+=1
  elif flagA:
    time+=B[t]
    t+=1
    cnt+=1
    if t==m:
      break
    
  else:
    time+=A[s]
    s+=1
    cnt+=1
    if s==n:
      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()))

sum = 0
i = 0
j = 0

while (sum + A[i]) <= K:
  sum += A[i]
  i += 1
  if i >= N:
    break
  
while (sum + B[j]) <= K:
  sum += B[j]
  j += 1
  if j >= M:
    break
  
max = i + j

if sum <= K:
  print(max)
else:
  while (0 < i and j < M):
    sum -= A[i-1] 
    i -= 1
    while (sum + B[j]) <= K:
      sum += B[j]
      j += 1
      if j >= M:
        break
    if (i + j) > max:
      max = (i + j)
  print(max)

Submission status: Wrong Answer

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

sum = 0
i = 0
j = 0

while (sum + A[i]) <= K:
  sum += A[i]
  i += 1
  if i >= N:
    break
  
while (sum + B[j]) <= K:
  sum += B[j]
  j += 1
  if j >= M:
    break
  
max = i + j

if sum <= K:
  print(max)
else:
  while (0 < i or j < M):
    sum -= A[i-1] 
    i -= 1
    while (sum + B[j]) <= K:
      sum += B[j]
      j += 1
      if j >= M:
        break
    if (i + j) > max:
      max = (i + j)
  print(max)

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.insert(0,0)
B.insert(0,0)
A2 = [0]
B2 = [0]
for i in range(1,N+1):
  A2.append(A2[i-1] + A[i])
  if A2[i] > K: break
for i in range(1,M+1):
  B2.append(B2[i-1] + B[i])
  if B2[i] > K: break
  
N = len(A2) - 1
M = len(B2) - 1
MAX_K = 10 ** 9
MAX_DEPTH = N+M
data = [0] * MAX_DEPTH

for i in range(1, N+M):
  value = MAX_K
  for aNum in range(i+1):
    bNum = i - aNum
    if aNum <= N and bNum <= M:
      tempValue = A2[aNum] + B2[bNum]
      if tempValue < value:
        value = tempValue
  if value > K:
    print(i-1)
    exit()
print(N+M)

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.insert(0,0)
B.insert(0,0)
for i in range(1,N+1):
  A[i] += A[i-1]
  if A[i] > K: break
for i in range(1,M+1):
  B[i] += B[i-1]
  if B[i] > K: break
MAX_K = 10 ** 9
MAX_DEPTH = N+M
data = [0] * MAX_DEPTH

for i in range(1, N+M+1):
  value = MAX_K
  for aNum in range(i+1):
    bNum = i - aNum
    if aNum <= N and bNum <= M:
      tempValue = A[aNum] + B[bNum]
      if tempValue < value:
        value = tempValue
  if value > K:
    print(i-1)
    exit()
print(N+M)

Submission status: Wrong Answer

Solution code:
import math
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.insert(0,0)
B.insert(0,0)
for i in range(1,N+1):
  A[i] += A[i-1]
for i in range(1,M+1):
  B[i] += B[i-1]
MAX_K = 10 ** 9
MAX_DEPTH = N+M
data = [0] * MAX_DEPTH

for i in range(1, N+M+1):
  value = MAX_K
  for aNum in range(1,i+1):
    bNum = i - aNum
    if aNum <= N and bNum <= M:
      tempValue = A[aNum] + B[bNum]
      if tempValue < value: value = tempValue
  if value >= K:
    print(i-1)
    exit()

Submission status: Wrong Answer

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

if N!=1:
    for i in range(1,N+1):
        A[i]+=A[i-1]
if M!=1:
    for i in range(1,M+1):
        B[i]+=B[i-1]
print(A)
print(B)
t=0
for i in range(N+1):
    for j in range(M+1):
        if A[i]+B[j]<=K and t<=i+j:
            t=i+j
print(t)

Submission status: Wrong Answer

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

ans=0
time=0

while (len(a)!=0 or len(b)!=0) and time < k:

    #print(ans,time)
    ans+=1

    if len(a)==0:
        time+=b.pop(0)
        continue

    if len(b)==0:
        time+=a.pop(0)
        continue
    
    if a[0] <= b[0]:
        time+=a.pop(0)
        continue

    if a[0] > b[0]:
        time+=b.pop(0)
        continue

if time > k:
    ans-=1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0
maxsum = 0

nsum = np.cumsum(n)
msum = np.cumsum(m)
for k in range(1,200001):
    if k > a[0]:
        break
    bsum = a[2] - nsum[k]
    if bsum < 0:
        break
    idx = np.abs(np.asarray(msum) - bsum).argmin()
    if msum[idx] > bsum:
        j = idx - 1
    else:
        j = idx
    i = k
    if maxsum < i + j:
        maxsum = i + j
print(str(maxsum))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0
maxsum = 0

nsum = np.cumsum(n)
msum = np.cumsum(m)
for k in range(1,a[0]):
    if k > a[0]:
        break
    bsum = a[2] - nsum[k]
    if bsum < 0:
        break
    idx = np.abs(np.asarray(msum) - bsum).argmin()
    if msum[idx] > bsum:
        j = idx - 1
    else:
        j = idx
    i = k
    if maxsum < i + j:
        maxsum = i + j
print(str(maxsum))

Submission status: Wrong Answer

Solution code:
import numpy

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

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0

nsum = numpy.cumsum(n)
msum = numpy.cumsum(m)
for k in range(400000):
    if i >= a[0]:
        while(nsum[i] + msum[j] <= a[2]):
            j += 1
            if j == a[1] and nsum[i] + msum[j] <= a[2]:
                j += 1
                break
            elif j > a[1]:
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(nsum[i] + msum[j] <= a[2]):
            i += 1
            if i == a[0] and nsum[i] + msum[j] <= a[2]:
                i += 1
                break
            elif i > a[0]:
                break
        ans = i + j - 1
        break
    elif nsum[i + 1] > msum[j + 1]:
        j += 1
    else:
        i += 1
    if nsum[i] + msum[j] > a[2]:
        ans = i + j - 1
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
import numpy

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

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0

nsum = numpy.cumsum(n)
msum = numpy.cumsum(m)
for k in range(400000):
    if i >= a[0]:
        while(nsum[i] + msum[j] <= a[2]):
            j += 1
            if j >= a[1] and nsum[i] + msum[j] <= a[2]:
                j += 1
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(nsum[i] + msum[j] <= a[2]):
            i += 1
            if i >= a[0] and nsum[i] + msum[j] <= a[2]:
                i += 1
                break
        ans = i + j - 1
        break
    if nsum[i + 1] > msum[j + 1]:
        j += 1
    else:
        i += 1
    if nsum[i] + msum[j] > a[2]:
        ans = i + j - 1
        if ans < 0:
            ans = 0
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Aug  5 15:03:01 2020

@author: Nagatsuka_Miku
"""
import numpy

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

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0

nsum = numpy.cumsum(n)
msum = numpy.cumsum(m)
for k in range(400000):
    if i >= a[0]:
        while(nsum[i] + msum[j] <= a[2]):
            j += 1
            if j >= a[1] and nsum[i] + msum[j] <= a[2]:
                j += 1
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(nsum[i] + msum[j] <= a[2]):
            i += 1
            if i >= a[0] and nsum[i] + msum[j] <= a[2]:
                i += 1
                break
        ans = i + j - 1
        break
    if nsum[i + 1] > msum[j + 1]:
        j += 1
    else:
        i += 1
    if nsum[i] + msum[j] > a[2]:
        ans = i + j - 1
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
import numpy

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

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0

nsum = numpy.cumsum(n)
msum = numpy.cumsum(m)
for k in range(400000):
    if i >= a[0]:
        while(nsum[i] + msum[j] <= a[2]):
            j += 1
            if j >= a[1] and nsum[i] + msum[j] <= a[2]:
                j += 1
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(nsum[i] + msum[j] <= a[2]):
            i += 1
            if i >= a[0] and nsum[i] + msum[j] <= a[2]:
                i += 1
                break
        ans = i + j - 1
        break
    if nsum[i] > msum[j]:
        j += 1
    else:
        i += 1
    if nsum[i] + msum[j] > a[2]:
        ans = i + j - 1
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
import numpy

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

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0

nsum = numpy.cumsum(n)
msum = numpy.cumsum(m)
print(nsum)
for k in range(400000):
    if i >= a[0]:
        while(nsum[i] + msum[j] <= a[2]):
            j += 1
            if j >= a[1] and nsum[i] + msum[j] <= a[2]:
                j += 1
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(nsum[i] + msum[j] <= a[2]):
            i += 1
            if i >= a[0] and nsum[i] + msum[j] <= a[2]:
                i += 1
                break
        ans = i + j - 1
        break
    if nsum[i] > msum[j]:
        j += 1
    else:
        i += 1
    if nsum[i] + msum[j] > a[2]:
        ans = i + j - 1
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
import numpy

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

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0

nsum = numpy.cumsum(n)
msum = numpy.cumsum(m)

for k in range(400000):
    if i >= a[0]:
        while(nsum[i] + msum[j] <= a[2]):
            j += 1
            if j == a[1] and nsum[i] + msum[j] <= a[2]:
                j += 1
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(nsum[i] + msum[j] <= a[2]):
            i += 1
            if i == a[0] and nsum[i] + msum[j] <= a[2]:
                i += 1
                break
        ans = i + j - 1
        break
    if nsum[i] > msum[j]:
        j += 1
    else:
        i += 1
    if nsum[i] + msum[j] > a[2]:
        ans = i + j - 1
        break
print(str(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, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

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

# print(a)
# print(b)
number = []
for i in range(1, len(a)+1):
    for j in range(1, len(b)+1):
        if k >= sum(a[:i]) + sum(b[:j]):
            number.append(i+j)
        else:
            break
if number == []:
    print(0)
else:
    print(max(number))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

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

i = 0
j = 0
bsum = 0
ans = 0
for k in range(400000):
    if i >= a[0]:
        while(bsum <= a[2]):
            bsum += m[j]
            j += 1
            if j >= a[1]:
                if bsum <= a[2]:
                    j += 1
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(bsum <= a[2]):
            bsum += n[i]
            i += 1
            if i >= a[0]:
                if bsum <= a[2]:
                    i += 1
                break
        ans = i + j - 1
        break
    if n[i] > m[j]:
        bsum += m[j]
        j += 1
    else:
        bsum += n[i]
        i += 1
    if bsum > a[2]:
        ans = i + j - 1
        if ans < 0:
            ans = 0
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

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

i = 0
j = 0
bsum = 0
ans = 0
for k in range(400000):
    if i >= a[0]:
        while(bsum <= a[2]):
            bsum += m[j]
            j += 1
            if j >= a[1]:
                if bsum <= a[2]:
                    j += 1
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(bsum <= a[2]):
            bsum += n[i]
            i += 1
            if i >= a[0]:
                if bsum <= a[1]:
                    i += 1
                break
        ans = i + j - 1
        break
    if n[i] > m[j]:
        bsum += m[j]
        j += 1
    else:
        bsum += n[i]
        i += 1
    if bsum > a[2]:
        ans = i + j - 1
        if ans < 0:
            ans = 0
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

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

i = 0
j = 0
bsum = 0
ans = 0
for k in range(400000):
    if i >= a[0]:
        while(bsum <= a[2]):
            bsum += m[j]
            j += 1
            if j >= a[1]:
                if bsum <= a[2]:
                    j += 1
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(bsum <= a[2]):
            bsum += n[i]
            i += 1
            if i >= a[0]:
                if bsum <= a[1]:
                    i += 1
                break
        ans = i + j - 1
        break
    if n[i] > m[j]:
        bsum += m[j]
        j += 1
    else:
        bsum += n[i]
        i += 1
    if bsum > a[2]:
        ans = i + j - 1
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

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

i = 0
j = 0
bsum = 0
ans = 0
for k in range(400000):
    if i >= a[0]:
        while(bsum <= a[2]):
            bsum += m[j]
            j += 1
            if j >= a[1]:
                j += 1
                break
        ans = i + j - 1
        break
    elif j >= a[1]:
        while(bsum <= a[2]):
            bsum += n[i]
            i += 1
            if i >= a[0]:
                i += 1
                break
        ans = i + j - 1
        break
    if n[i] > m[j]:
        bsum += m[j]
        j += 1
    else:
        bsum += n[i]
        i += 1
    if bsum > a[2]:
        ans = i + j - 1
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

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

i = 0
j = 0
bsum = 0
ans = 0
for k in range(400000):
    if i >= a[0]:
        while(bsum <= a[2]):
            bsum += m[j]
            j += 1
            if j >= a[1]:
                break
        ans = i + j
        break
    elif j >= a[1]:
        while(bsum <= a[2]):
            bsum += n[i]
            i += 1
            if i >= a[0]:
                break
        ans = i + j
        break
    if n[i] > m[j]:
        bsum += m[j]
        j += 1
    else:
        bsum += n[i]
        i += 1
    if bsum > a[2]:
        ans = i + j - 1
        break
print(str(ans))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

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

i = 0
j = 0
bsum = 0
ans = 0
for k in range(400000):
    if i >= a[0]:
        while(bsum <= a[2]):
            bsum += m[j]
            j += 1
            if j >= a[1]:
                break
        ans = i + j
        break
    elif j >= a[1]:
        while(bsum <= a[2]):
            bsum += n[i]
            i += 1
            if i >= a[0]:
                break
        ans = i + j
        break
    if n[i] > m[j]:
        bsum += m[j]
        j += 1
    else:
        bsum += n[i]
        i += 1
    if bsum > a[2]:
       ans = i + j - 1
print(str(ans))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

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

i = 0
j = 0
bsum = 0
ans = 0
for k in range(400000):
    if i >= a[0]:
        while(bsum <= a[2]):
            bsum += m[j]
            j += 1
            if j >= a[1]:
                break
        ans = i + j
        break
    elif j >= a[1]:
        while(bsum <= a[2]):
            bsum += n[i]
            i += 1
            if i >= a[0]:
                break
        ans = i + j
        break
    if n[i] > m[j]:
        bsum += m[j]
        j += 1
    else:
        bsum += n[i]
        i += 1
    if bsum > a[2]:
       ans = i + j
print(str(ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n,m,k = MI()
a = deque(LI())
b = deque(LI())
ans = 0
while k > 0 and len(a) + len(b) > 0:
    if len(a) == 0 and len(b) > 0:
        book2 = b.popleft()
        k -= book2
        if k >= 0:
            ans += 1
    if len(b) == 0 and len(a) > 0:
        book = a.popleft()
        k -= book
        if k >= 0:
            ans += 1
    if len(a) > 0 and len(b) > 0:
        book = a.popleft()
        book2 = b.popleft()
        if book <= book2:
            k -= book
            if k >= 0:
                ans += 1
                b.appendleft(book2)
        else:
            k -= book2
            if k >= 0:
                ans += 1
                a.appendleft(book)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n,m,k = MI()
a = deque(LI())
b = deque(LI())
ans = 0
while k > 0 and len(a) + len(b) > 0:
    if len(a) > 0:
        book = a.popleft()
    if len(a) == 0:
        book = 10**10
    if len(b) > 0:
        book2 = b.popleft()
    elif len(b) == 0:
        book2 = 10**10
    if book < book2:
        k -= book
        if k > 0:
            ans += 1
            b.appendleft(book2)
    if book > book2:
        k -= book2
        if k > 0:
            ans += 1
            a.appendleft(book)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n,m,k = MI()
a = deque(LI())
b = deque(LI())
ans = 0
while k > 0 and len(a) + len(b) > 0:
    if len(a) > 0:
        book = a.popleft()
    if len(a) == 0:
        book = 10**10
    if len(b) > 0:
        book2 = b.popleft()
    elif len(b) == 0:
        book2 = 10**10
    if book < book2:
        k -= book
        if k > 0:
            ans += 1
    if book > book2:
        k -= book2
        if k > 0:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n,m,k = MI()
a = deque(LI())
b = deque(LI())
ans = 0
while k > 0 and len(a) + len(b) > 0:
    if len(a) > 0:
        book = a.popleft()
    elif len(a) == 0:
        book = 10**10
    if len(b) > 0:
        book2 = b.popleft()
    elif len(b) == 0:
        book2 = 10**10
    if book < book2:
        k -= book
        if k > 0:
            ans += 1
    else:
        k -= book2
        if k > 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()))

# print(a)
# print(b)
# print(min(n, m))
x_min = min(n, m)
x_max = max(n, m)
flag = 0
for i in range(x_min):
    y_min = min(a[i], b[i])
    y_max = max(a[i], b[i])

    k -= y_min
    if k >= 0:
        flag += 1
        k -= y_max
    else:
        print(flag)
        exit()

    if k >= 0:
        flag += 1
    else:
        print(flag)
        exit()

for i in range(x_min, x_max):
    if x_max == n:
        y = a[i]
    else:
        y = b[i]
    k -= y
    if k >= 0:
        flag += 1
    else:
        print(flag)
        exit()

print(len(a) + len(b))

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()
for i in range(len(c)):
    if k < 0:
        print(i-1)
        exit()
    else:
        k -= c[i]
print(len(c))

Submission status: Wrong Answer

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

a[0:0]=[0]
b[0:0]=[0]

ans, j = 0, m

for i in range(n + 1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Submission status: Wrong Answer

Solution code:

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

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

cnt = 0
t = 0
x = 0
y = 0
for i in range(N + M):
    if x == N:
        t = t + B[y]
        y += 1
        cnt += 1
        if t > K:
            print(cnt - 1)
            exit()
    elif y == M:
        t = t + A[x]
        x += 1
        cnt += 1
        if t > K:
            print(cnt - 1)
            exit()
    else:
        t = t + min(A[x], B[y])
        if A[x] != B[y]:
            if A[x] == min(A[x],B[y]):
                x += 1
            elif B[y] == min(A[x],B[y]):
                y += 1
        else:
            a = x
            b = y
            while(A[a] != B[b]):
                a += 1
                b += 1
            if A[a] == min(A[a],B[b]):
                x += 1
            elif B[b] == min(A[a],B[b]):
                y += 1
        cnt += 1
        if t > K:
            print(cnt-1)
            exit()

print(N + M)

Submission status: Wrong Answer

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


time = 0
cont_a = 0
cont_b = 0

while True:
    if (n > 0) and (m > 0):
        if a[cont_a] > b[cont_b]:
            if time + b[cont_b] <= k:
                time += b[cont_b]
                cont_b += 1
                m -= 1
            else:
                break
        else:
            if time + a[cont_a] <= k:
                time += a[cont_a]
                cont_a += 1
                n -= 1
            else:
                break
                
    elif (n > 0) and (m <= 0):
        if time + a[cont_a] <= k:
            time += a[cont_a]
            cont_a += 1
            n -= 1
        else:
            break
        
    elif (n <= 0) and (m > 0):
        if time + b[cont_b] <= k:
            time += b[cont_b]
            cont_b += 1
            m -= 1
        else:
            break
    else:
        break
            
print(cont_a + cont_b)

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
cont_a = 0
cont_b = 0

while True:
    if (n > 0) and (m > 0):
        if a[cont_a] > b[cont_b]:
            if time + b[cont_b] < k:
                time += b[cont_b]
                cont_b += 1
                m -= 1
            else:
                break
        else:
            if time + a[cont_a] < k:
                time += a[cont_a]
                cont_a += 1
                n -= 1
            else:
                break
                
    elif (n > 0) and (m <= 0):
        if time + a[cont_a] < k:
            time += a[cont_a]
            cont_a += 1
            n -= 1
        else:
            break
        
    elif (n <= 0) and (m > 0):
        if time + b[cont_b] < k:
            time += b[cont_b]
            cont_b += 1
            m -= 1
        else:
            break
            
print(cont_a + cont_b)

Submission status: Wrong Answer

Solution code:
#ABC172 C

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

a=[]
b=[]
i=0
j=0
s=0
t=0
while i<n:
  a.append(s+a_[i])
  s=a[i]
  i+=1
while j<m:
  b.append(t+b_[j])
  t=b[j]
  j+=1
  
  
def binary_search(x):
  if x<0:
    return 0
  high=m
  low=0
  while (high-low)>1:
    mid=(high+low)//2
    if b[mid]>x:
      high=mid

    else:
      low=mid
      
  #print(high)
  return high

ans=0
for i in range(n):
  u=k-a[i]
  #print(i)
  #print(u)
  if u<=0:
    break
  ans_=i+1+binary_search(u)
  #print(ans_)
  ans=max(ans,ans_)


print(ans)