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:
## necessary imports
import sys
input = sys.stdin.readline
#from math import ceil, floor, factorial;

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp

## gcd function
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
    if(k > n - k): 
        k = n - k 
    res = 1
    for i in range(k): 
        res = res * (n - i) 
        res = res / (i + 1) 
    return int(res) 

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
    hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        else:
            hi = mid
    return lo

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;


# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e7 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve() 
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()))
## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

n, m, k = int_array(); a = int_array()[::-1];
b = int_array()[::-1]; ans = 0; time = 0;
while(time < k):
    if a and b:
        if a[-1] <= b[-1]:
            if(a[-1] + time <= k):
                ans += 1; time += a.pop();
            else:
                break;
        else:
            if(b[-1] + time <= k):
                ans += 1; time += b.pop();
            else:
                break;
    else:
        if a:
            if(a[-1] + time <= k):
                ans += 1; time += a.pop();
            else:
                break;
        elif b:
            if(b[-1] + time <= k):
                ans += 1; time += b.pop();
            else:
                break;
        else:
            break;

print(ans);

Submission status: Wrong Answer

Solution code:
## necessary imports
import sys
input = sys.stdin.readline
#from math import ceil, floor, factorial;

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp

## gcd function
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
    if(k > n - k): 
        k = n - k 
    res = 1
    for i in range(k): 
        res = res * (n - i) 
        res = res / (i + 1) 
    return int(res) 

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
    hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        else:
            hi = mid
    return lo

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;


# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e7 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve() 
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()))
## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

n, m, k = int_array(); a = int_array()[::-1];
b = int_array()[::-1]; ans = 0; time = 0;
while(time < k):
    if a and b:
        if a[-1] <= b[-1]:
            ans += 1; time += a.pop();
        else:
            ans += 1; time += b.pop();
    else:
        if a:
            ans += 1; time += a.pop();
        elif b:
            ans += 1; time += b.pop();
        else:
            break;
if time > k:
    ans -= 1;
print(ans);

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10**7)

ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

n, m, k = na()
a = na()
b = na()

sa = sum(a)
sb = sum(b)
ca = n - 1
cb = m - 1

ans = 0
while ca >= 0 and cb >= 0:
    if sa > k:
        sa -= a[ca]
        ca -= 1
        continue
    if sb > k:
        sb -= b[cb]
        cb -= 1
        continue
    
    ans = max(ans, ca + 1, cb + 1)
    if sa + sb <= k:
        ans = max(ans, ca + cb + 2)
        break
    elif cb < 0 or ca < 0:
        ans = max(ans, max(ca + 1, cb + 1))
        break
    else:
        if a[ca] < b[cb]:
            sb -= b[cb]
            cb -= 1
        else:
            sa -= a[ca]
            ca -= 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()))
time = 0
nanko = 0
while time < k:
#    print(a,b,time,nanko)
    if n != 0 and m != 0:
        if a[0] <= b[0] and time + a[0] <= k:
#            print("A")
            time += a[0]
            del a[0]
            nanko += 1
            n -= 1
        elif a[0] > b[0] and time + b[0] <= k:
#            print("B")
            time += b[0]
            del b[0]
            nanko += 1
            m -= 1
        else:
#            print("C")
            break
    elif n != 0 and m == 0:
        if time + a[0] <= k:
#            print("D")
            time += a[0]
            del a[0]
            nanko += 1
            n -= 1
        else:
#            print("E")
            break
    elif n == 0 and m != 0:
        if time + b[0] <= k:
#            print("F")
            time += b[0]
            del b[0]
            nanko += 1
            m -= 1
        else:
#            print("G")
            break
    else:
#        print("H")
        break
#print("Answer",a,b,time,nanko)
print(nanko)
"""
    print(a,b,time,nanko)
    if a and b:
        if a[0] <= b[0]:
            time += a[0]
            if time <= k:
                del a[0]
                nanko += 1
            else:
                time -= a[0]
                break
        else:
            time += b[0]
            if time <= k:
                del b[0]
                nanko += 1
            else:
                time -= b[0]
                break
    elif not a and b:
        time += b[0]
        if time <= k:
            del b[0]
            nanko += 1
        else:
            time -= b[0]
            break
    elif a and not b:
        time += a[0]
        if time <= k:
            del a[0]
            nanko += 1
        else:
            time -= a[0]
            break
    else:
        break
"""

Submission status: Wrong Answer

Solution code:
import bisect
import sys

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

a_accumulated = [0] * n
b_accumulated = [0] * m

for idx, a in enumerate(A):
    a_accumulated[idx] += a_accumulated[idx - 1] + a # idx == 0の場合はa_accumulated[-1]を参照するが、それは0初期化されているので問題ない。

for idx, b in enumerate(B):
    b_accumulated[idx] += b_accumulated[idx - 1] + b

a_limit = bisect.bisect_right(a_accumulated, k)
if a_limit == 0:
    position = bisect.bisect_right(b_accumulated, k)
    print(position)
    sys.exit(0)

best_num = 0
for i in reversed(range(0, a_limit)):
    position = bisect.bisect_right(b_accumulated, k - a_accumulated[i])
    best_num = max(best_num, i + position + 1)
print(best_num)

Submission status: Wrong Answer

Solution code:
import bisect
import sys

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

a_accumulated = [0] * n
b_accumulated = [0] * m

for idx, a in enumerate(A):
    a_accumulated[idx] += a_accumulated[idx - 1] + a # idx == 0の場合はa_accumulated[-1]を参照するが、それは0初期化されているので問題ない。

for idx, b in enumerate(B):
    b_accumulated[idx] += b_accumulated[idx - 1] + b

a_limit = bisect.bisect_right(a_accumulated, k)
if a_limit == 0:
    print(0)
    sys.exit(0)

best_num = 0
for i in reversed(range(0, a_limit)):
    position = bisect.bisect_right(b_accumulated, k - a_accumulated[i])
    best_num = max(best_num, i + position + 1)
print(best_num)

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()))
sumbook,sumt,i,j=0,0,0,0
while True:
  if i<=(n-1) and j<=(m-1):
    if a[i]>b[j]:
      sumt+=b[j]
      j+=1
    else:
      sumt+=a[i]
      i+=1
  elif i>(n-1) and j<=(m-1):
    sumt+=b[j]
    j+=1
  elif i<=(n-1) and j>(m-1):
    sumt+=a[i]
    i+=1
  if sumt>k:
    break
  elif sumt==k:
    sumbook+=1
    break
  sumbook+=1
print(sumbook)

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()))
sumbook,sumt,i,j=0,0,0,0
while True:
  if i<=(n-1) and j<=(m-1):
    if a[i]>b[j]:
      sumt+=b[j]
      j+=1
    else:
      sumt+=a[i]
      i+=1
  elif i>(n-1) and j<=(m-1):
    sumt+=b[j]
    j+=1
  elif i<=(n-1) and j>(m-1):
    sumt+=a[i]
    i+=1
#=がないとぴったりの時にループから抜け出せなくなる
#累計冊数に1を足さないとぴったりの時が数えられない
  if sumt>=k:
    sumbook+=1
    break
  sumbook+=1
print(sumbook)

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
nanko = 0
while time <= k:
    if a and b:
        if a[0] <= b[0]:
            time += a[0]
            if time <= k:
                del a[0]
                nanko += 1
            else:
                time -= a[0]
                break
        else:
            time += b[0]
            if time <= k:
                del b[0]
                nanko += 1
            else:
                time -= b[0]
                break
    elif not a and b:
        time += b[0]
        if time <= k:
            del b[0]
            nanko += 1
        else:
            time -= b[0]
            break
    elif a and not b:
        time += a[0]
        if time <= k:
            del a[0]
            nanko += 1
        else:
            time -= a[0]
            break
    else:
        break
print(nanko)

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
t = 0
i = 0
j = 0

while t < K:
    if(A[i]>=B[j] and j <= (len(B)-1)):
        t += B[j]
        ans += 1
        if(j < len(B)-1):
            j += 1
    elif(A[i]<=B[j] and i <= (len(B)-1)):
        t += A[i]
        ans += 1
        if(i < len(A)-1):
            i += 1
    else:
      break
    

print(ans-1)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
lst1=list(map(int,input().strip().split()))[:n]
lst2=list(map(int,input().strip().split()))[:m]
s=0
count=0 
n1=0 
n2=0
while(s<k):
    if(n1==n and n2!=m):
        count+=1
        s+=lst2[n2]
        n2+=1
    elif(n2==m and n1!=n):
        count+=1 
        s+=lst1[n1]
        n1+=1
    elif(lst1[n1]>lst2[n2] and (lst2[n2]+s)<=k and n1!=n and n2!=m):
        count+=1 
        s+=lst2[n2]
        n2+=1
    elif(lst1[n1]<lst2[n2] and (lst1[n1]+s)<=k):
        count+=1 
        s+=lst1[n1]
        n1+=1
    else:
        break 
print(count)

Submission status: Wrong Answer

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

a,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])
print(a)
print(b)

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()))
ans = 0
t = 0
i = 0
j = 0

while t < K:
    if(A[i]>=B[j]):
        t += B[j]
        ans += 1
        if(j < len(B)-1):
            j += 1
    elif(A[i]<=B[j]):
        t += A[i]
        ans += 1
        if(i < len(A)-1):
            i += 1
    

print(ans-1)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = []
    for x in range(1,n+1):
        sumA = sum(A[0:x])
        for y in range(1,m+1):
            sumB = sum(B[0:y])
            if sumA + sumB < k:
                C.append(sumA + sumB)
    print(C)
main()

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = []
    for x in range(n+1):
        sumA = sum(A[0:x+1])
        for y in range(m+1):
            sumB = sum(B[0:y+1])
            if sumA + sumB <= k:
                C.append(sumA + sumB)
    print(C)
main()

Submission status: Wrong Answer

Solution code:
def INT():
    return int(input())

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

def LI():
    return list(map(int, input().split()))

N, M, K = MI()
A = [0] + LI()
B = [0] + LI()

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

for i in range(1, M + 1):
    B[i] += B[i - 1]
    
    if B[i] <= K:
        ans = i

ans = 0

for bk_a in range(1, N + 1):
    time = A[bk_a]

    if time > K:
        break
        
    l, r = -1, M + 1
    while abs(l - r) > 1:
        bk_b = (l + r) // 2

        if time + B[bk_b] <= K:
            l = bk_b
        else:
            r = bk_b
    
    bk_b = max(0, l)
    ans = max(ans, bk_a + bk_b)

print(ans)

Submission status: Wrong Answer

Solution code:
def INT():
    return int(input())

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

def LI():
    return list(map(int, input().split()))

N, M, K = MI()
A = [0] + LI()
B = [0] + LI()
ans = 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]
    
    if B[i] <= K:
        ans = i

for bk_a in range(1, N + 1):
    time = A[bk_a]

    if time > K:
        break
        
    l, r = -1, M + 1
    while abs(r - l) > 1:
        bk_b = (l + r) // 2

        if time + B[bk_b] <= K:
            l = bk_b
        else:
            r = bk_b
        
    ans = max(ans, bk_a + bk_b)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
lst1=list(map(int,input().strip().split()))[:n]
lst2=list(map(int,input().strip().split()))[:m]
s=0
count=0 
n1=0 
n2=0
while(s<k):
    if(n1==n):
        count+=1
        s+=lst2[n2]
        n2+=1
    elif(n2==m):
        count+=1 
        s+=lst1[n1]
        n1+=1
    elif(lst1[n1]>lst2[n2] and (lst2[n2]+s)<=k and n1!=n and n2!=m):
        count+=1 
        s+=lst2[n2]
        n2+=1
    elif(lst1[n1]<lst2[n2] and (lst1[n1]+s)<=k):
        count+=1 
        s+=lst1[n1]
        n1+=1
    else:
        break 
print(count)

Submission status: Wrong Answer

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

a=0;b=0
cnt=0
while (a < len(A) or b < len(B)) and K > 0:
  if a < len(A) and b < len(B):
    a_ = A[a]
    b_ = B[b]
    
    if a_ > K and b_ > K:
        break
      
    if a_ < b_ and a_ <= K:
        cnt += 1
        K -= a_
        a += 1
    elif a_ >= b_ and b_ <= K:
        cnt += 1
        K -= b_
        b += 1
  elif a < len(A):
    if A[a] <= K:
      cnt += 1
      K -= A[a]
      a += 1
  elif b < len(B):
    if B[b] <= K:
      cnt += 1
      K -= B[b]
      b += 1
  else:
    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()))
ans_list=[]
S=0
A_count=0
B_count=0

for i in range(len(A)):
  S += A[i]
  A_count += 1
  for j in range(len(B)-B_count):
    if S <= K:
      S += B[B_count]
      B_count += 1
    elif S > K and B_count != 0:
      S -= B[B_count-1]
      B_count -= 1
      if S <= K:
        break
    else:
      S -= A[i]
      A_count -= 1
      ans_list.append(A_count)
      break

  ans_list.append(A_count+B_count)

print(max(ans_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()))

a=0;b=0
cnt=0
while a < len(A) and b < len(B) and K > 0:
    a_ = A[a]
    b_ = B[b]
    
    if a_ > K and b_ > K:
        break
      
    if a_ < b_ and a_ <= K:
        cnt += 1
        K -= a_
        a += 1
    elif a_ >= b_ and b_ <= K:
        cnt += 1
        K -= b_
        b += 1
    
print(cnt)

Submission status: Wrong Answer

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

a=0;b=0
cnt=0
while a < len(A) and b < len(B) and K > 0:
    a_ = A[a]
    b_ = B[b]
    print(a_, b_,K)
    
    if a_ > K and b_ > K:
        break
      
    if a_ < b_ and a_ <= K:
        cnt += 1
        K -= a_
        a += 1
    elif a_ >= b_ and b_ <= K:
        cnt += 1
        K -= b_
        b += 1
    
print(cnt)

Submission status: Wrong Answer

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

for i in range(len(A)):
  S += A[i]
  A_count += 1
  for j in range(len(B)-B_count):
    if S <= K:
      S += B[B_count]
      B_count += 1
    elif S > K and B_count != 0:
      S -= B[B_count-1]
      B_count -= 1
      break
    else:
      S -= A[i]
      A_count -= 1
      ans_list.append(A_count)
      break

  ans_list.append(A_count+B_count)

print(max(ans_list))

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
B=list(map(int,input().split()))
B.insert(0,0)
best=0
for a in range(N):
    atime=0
    btime=0
    for i in range(a+1):
        atime=atime+A[i]
        if atime>K:
          break
    else:
        for b in range(M):
            btime=btime+B[b]
            if atime+btime>K:
                book=a+b-1
                if book>best:
                    best=book
                break
        else:
            book=a+b
            if book>best:
                best=book
print(best)

Submission status: Wrong Answer

Solution code:
def INT():
    return int(input())

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

def LI():
    return list(map(int, input().split()))

N, M, K = MI()
A = LI()
B = LI()

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

for i in range(1, M):
    B[i] += B[i - 1]
    
bk_a = N
ans = 0
flg = False

for i in range(N):
    bk_a = N - i
    time = A[bk_a - 1]
    
    l, r = -1, M + 1 
    while abs(l - r) > 1:
        bk_b = (l + r) // 2
        
        if time + B[bk_b - 1] < K:
            l = bk_b
        else:
            r = bk_b
            
    if A[bk_a - 1] + B[bk_b - 1] <= K:
        ans = max(ans, bk_a + bk_b)
        flg = True
        
print(ans if flg else 0)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K=map(int,input().split())
SumA=[0]*(N+1)
SumB=[0]*(M+1)
A=list(map(int, input().split()))
B=list(map(int,input().split()))
for i in range(1,N+1):
    SumA[i]= A[i-1]+SumA[i-1]
for i in range(1,M+1):
    SumB[i] = B[i-1]+SumB[i-1]

ans = 0
for i in range(N+1):
    num = i
    rest = K-SumA[i]
    if rest<=0:
        break;
    num += bisect.bisect_right(SumB, rest)-1
    ans = max(num, ans)

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

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

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

a = [0]+a
b = [0]+b

i = 0
j = m
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

sumA = np.cumsum(A)
sumB = np.cumsum(B)
#print(sumA)
#print(sumB)
ans=0

for i in range(n+1):
    ab=sumA[i]+sumB
    s=sum(ab<=k)
    if s-1>0:
        x=i+s-1
        if x>ans:
            ans=x
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

sumA = np.cumsum(A)
sumB = np.cumsum(B)
#print(sumA)
#print(sumB)
la=len(sumA)
ans=0

for i in range(la):
    ab=sumA[i]+sumB
    if sum(ab<=k)-1>0:
        x=i+sum(ab<=k)-1
        if x>ans:
            ans=x
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

bookA = deque(list(map(int, input().split())), N)
bookB = deque(list(map(int, input().split())), M)

cnt = 0
while K >= 0:
    if len(bookA) == 0 and len(bookB) == 0:
        break
    elif len(bookA) > 0 and len(bookB) == 0:
        K -= bookA.popleft()
    elif len(bookA) == 0 and len(bookB) > 0:
        K -= bookB.popleft()
    elif len(bookA) > 0 and len(bookB) > 0:
        if bookA[0] <= bookB[0]:
            K -= bookA.popleft()
        else:
            K -= bookB.popleft()
    if K >= 0:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

def calc_acc(n,k,l):
    acc_l = [k]*n
    acc_l[0] = l[0] 
    for i in range(1,n):
        acc_l[i] = acc_l[i-1] + l[i]
        if acc_l[i] > k:
            break
    #print(acc_l)
    return acc_l

def read_book(a,b,k):
    #print(a)
    #print(b)
    book = 0
    for i,va in enumerate(a):
        for j,vb in enumerate(b):
            if va + vb > k:
                #print("break")
                break
            else:
                #print(i,j,book,va,vb,va+vb,k)
                book = max([i + j + 2,book])
    return book

def tsundoku(n,m,k,a,b):
    acc_a = calc_acc(n,k,a)
    acc_b = calc_acc(m,k,b)
    book_a = read_book(acc_a,acc_b,k)
    book_b = read_book(acc_b,acc_a,k)

    print(max([book_a,book_b]))
    
if __name__ == "__main__":
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    tsundoku(n,m,k,a,b)

Submission status: Wrong Answer

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

def calc_acc(n,k,l):
    acc_l = [k]*n
    acc_l[0] = l[0] 
    for i in range(1,n):
        acc_l[i] = acc_l[i-1] + l[i]
        if acc_l[i] >= k:
            break
    #print(acc_l)
    return acc_l

def read_book(a,b,k):
    #print(a)
    #print(b)
    book = 0
    for i,va in enumerate(a):
        for j,vb in enumerate(b):
            if va + vb > k:
                #print("break")
                break
            else:
                #print(i,j,book,va,vb,va+vb,k)
                book = max([i + j + 2,book])
    return book

def tsundoku(n,m,k,a,b):
    acc_a = calc_acc(n,k,a)
    acc_b = calc_acc(m,k,b)
    book_a = read_book(acc_a,acc_b,k)
    book_b = read_book(acc_b,acc_a,k)

    print(max([book_a,book_b]))
    
if __name__ == "__main__":
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    tsundoku(n,m,k,a,b)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

bookA = deque(list(map(int, input().split())), N)
bookB = deque(list(map(int, input().split())), M)

cnt = 0
while K >= 0:
    if len(bookA) == 0 and len(bookB) == 0:
        break
    elif len(bookA) > 0 and len(bookB) == 0:
        K -= bookA.popleft()
    elif len(bookA) == 0 and len(bookB) > 0:
        K -= bookB.popleft()
    elif len(bookA) > 0 and len(bookB) > 0:
        if bookA[0] >= bookB[0]:
            K -= bookA.popleft()
        else:
            K -= bookB.popleft()
    if K >= 0:
        cnt += 1

print(cnt)