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.append(10**10)
b.append(10**10)
cnt = 0
ca = 0
cb = 0

for i in range(len(a) + len(b)):
    if a[ca] == b[cb] == 10**10:
        break
    if cnt < k:
        if a[ca] < b[cb]:
            cnt += a[ca]
            if cnt <= k:
                ca += 1
            else:
                break
        else:
            cnt += b[cb]
            if cnt <= k:
                cb += 1
            else:
                break
print(ca + cb)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()


from collections import deque  #listよりdequeの方が両端へのアクセスは計算量が少ない
def main():
    n, m, k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    e = [2 * (10 ** 9)] * max(n, m)
    a = a + [2 * (10 ** 9)] * m
    b = b + [2 * (10 ** 9)] * n
    ti = 0
    c = 0
    while c <= n + m:
        if a[0] <= b[0] or len(a) == 0:
            ti += a[0]
            a.pop(0)
            if ti > k:
                break
            c += 1
        elif a[0] >= b[0] or len(b) == 0:
            ti += b[0]
            b.pop(0)
            if ti > k:
                break
            c += 1
    print(c)



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

c = []
         
while((len(a) != 0 or len(b) != 0)):
  if(len(a) == 0):
    c.append(b[0]);b.pop(0);continue
  if(len(b) == 0):
    c.append(a[0]);a.pop(0);continue
  
  if(a[0] > b[0]):
    c.append(b[0]);b.pop(0);continue
  else:
    c.append(a[0]);a.pop(0);continue

tmp = 0
ans = 0
for i in c:
  tmp += i
  if(tmp <= k):ans+=1
  else:print(ans);exit()
print(ans)

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]"):
    cur = sum(A)
    for i in range(N-1,-1,-1):
        if cur>K: cur -= A[i]
        else:break
    if cur==0:
        max_k = 0
        l = 0
    else:
        max_k = i+1
        l = 1
    max_pk = max_k

    p = 0
    while(p<M):
        if cur+B[p] <= K:
            cur+=B[p]
            max_k = max(max_pk+p+1, max_k)
            p+=1
        else:
            break

    # print(cur,max_k)
    if l ==1:
        for q in range(i,-1,-1):
            cur -= A[q]
            while(p<M):
                if cur+B[p] <= K:
                    cur+=B[p]
                    max_k = max(q+1+p+1, max_k)
                    p+=1
                else:
                    break
    print(max_k)





    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
l = input()
l = l.split()
n,m,k = l[0], l[1], int(l[2])
a = input().split()
b = input().split()

ans = 0

x,y = 0, 0

while k > 0:
    if x >= int(n) and y <= int(m) - 1:
        if k - int(b[y]) >= 0:
            k -= int(b[y])
            y += 1
            ans+=1
        else:
            break
    elif y >= int(m) and x <= int(n) - 1:
        if k - int(a[x]) >= 0:
            k -= int(a[x])
            x += 1
            ans+=1
        else:
            break
    elif int(a[x]) <= int(b[y]):
        if k - int(a[x]) >= 0:
            k -= int(a[x])
            x += 1
            ans+=1
        else:
            break
    elif int(a[x]) >= int(b[y]):
        if k - int(b[y]) >= 0:
            k -= int(b[y])
            y += 1
            ans+=1
        else:
            break
    else: break

print(ans)

Submission status: Wrong Answer

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

A = sorted(A)
B = sorted(B)

ans = 0
for i in range(200000):

    try:
        K = K - A[i]
        if K < 0:
            break
        ans = ans + 1
    except:
        pass

    try:
        K = K -B[i]
        if K < 0:
            break
        ans = ans + 1
    except:
        pass
    
    if K < 0:
        break
print(ans)

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


large = 10**10
time = 0
ans = 0
while (len(A) != 0 or len(B) != 0):
    a = large
    b = large

    if len(A)!=0:
        a = A[0]
    if len(B)!=0:
        b = B[0]

    if a < b:
        if time+a > K:
            break
        time += a
        A = A[1:]
        ans += 1
    else:
        if time+b > K:
            break
        time += b
        B = B[1:]
        ans += 1


print(ans)

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

cnt = 0
for i in range(len(a)):
	if a[i]<=k:
		k-=a[i]
		cnt+=1
for i in range(len(b)):
	if b[i]<=k:
		k-=b[i]
		cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
    N, M, K = map(int, readline().split())
    A = deque([int(i) for i in readline().split()])
    B = deque([int(i) for i in readline().split()])
    cnt = 0
    while (len(A) > 0) or (len(B) > 0): 
        if (len(A) > 0) and (len(B)) > 0:
            a = A.popleft()
            b = B.popleft()
            if a <= b:
                K -= a
                B.appendleft(b)
            else:
                K -= b
                A.appendleft(a)
        elif (len(A) > 0) and (len(B) == 0):
            a = A.popleft()
            K -= a
        elif (len(A) == 0) and (len(B) > 0):
            b = B.popleft()
            K -= b
        if K >= 0:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import itertools
n ,m ,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a = list(itertools.accumulate(a))
b = list(itertools.accumulate(b))
A =bisect.bisect_left(a,k)
count=0
if b[0]>k:
  print(A)
  exit()
if a[0]>k:
  print(bisect.bisect_left(b,k))
  exit()

for i in range(A,0,-1):
  ans=k-a[i-1]
  B =bisect.bisect_left(b,ans)
  if B<m:
    if b[B]==ans:
      B+=1
  count=max(count,i+B)
print(count)

Submission status: Wrong Answer

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

    a = 0
    b = 0

    ans = 0

    ib = 0
    while True:
        if ib != M and b + B[ib] <= K:
            b += B[ib]
            ib += 1
        else:
            break
    for ia in range(N):
        while a + A[ia] + b > K:
            if ib == 0:
                return ans
            ib -= 1
            b -= B[ib]
        a += A[ia]
        ans = max(ans,ia+ib+1)

    return ans

print(hoge())

Submission status: Wrong Answer

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

count = 0
sum = 0
for i in a:
    sum += i
    if sum > k:
        break
    count += 1;
    
print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split(" "));
arr = list(map(int,input().split(" ")));
brr = list(map(int,input().split(" ")));
i = 0;
j = 0;
cur = 0;
c = 0;
while(i<n and j<m):
  if(arr[i] > brr[j]):
    if(k > cur + brr[j]):
      c+=1;
      cur+=brr[j];
      j+=1;
    else:
      break;
  else:
    if(k > cur + arr[i]):
      c+=1;
      cur+=arr[i];
      i+=1;
    else:
      break;
while(i<n):
  if(k > cur + arr[i]):
      c+=1;
      cur+=arr[i];
      i+=1;
  else:
    break;
while(j<m):
  if(k > cur + brr[j]):
    c+=1;
    cur+=brr[j];
    j+=1;
  else:
    break;
print(c);

Submission status: Wrong Answer

Solution code:

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

N_arr = input().split(" ")
M_arr = input().split(" ")

cnt = 0
i_N = 0 
i_M = 0

def check_next(i_N, i_M):
    if(i_N+1 < N):
        N_top_next = int(N_arr[i_N+1])
    else:
        N_top_next = 10000000000

    if(i_M+1 < M):
        M_top_next = int(M_arr[i_M+1])
    else:
        M_top_next = 10000000000


    if(N_top_next > M_top_next):
        return "M"
    
    elif(N_top_next == M_top_next):
        return check_next(i_N+1, i_M+1)

    else:
        return "N"

while(True):
    if(i_N < N):
        N_top = int(N_arr[i_N])
    else:
        N_top = 10000000000

    if(i_M < M):
        M_top = int(M_arr[i_M])
    else:
        M_top = 10000000000

    if(N_top <= K or M_top <= K):
        if(N_top > M_top):
            K = K - M_top
            i_M += 1
        elif(N_top == M_top):
            flag = check_next
            if(flag == "N"):
                K = K - N_top
                i_N += 1
            else:
                K = K - M_top
                i_M += 1
        else:
            K = K - N_top
            i_N += 1
        cnt += 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()))
cnt = 0
time = 0
A.extend(B)
A.sort()
if A[0] > K :
    print(0)
else :
    for i in range(len(A)) :
        time += A[i]
        if K >= time :
            cnt += 1
        else :
            break
    print(cnt)

Submission status: Wrong Answer

Solution code:
line = input().strip().split()
n = int(line[0])
m = int(line[1])
k = int(line[2])

line = input().strip().split()
a = []
for i in line:
    a.append(int(i))

line = input().strip().split()
b = []
for i in line:
    b.append(int(i))

sum_a = [0]
sum = 0
for i in range(n):
    sum += a[i]
    sum_a.append(sum)

sum_b = [0]
sum = 0
for i in range(m):
    sum += b[i]
    sum_b.append(sum)

sum_a2 = [i for i in sum_a if i <= k]
sum_b2 = [i for i in sum_b if i <= k]

tmp = [0, 0]
for i in range(len(sum_a2)):
    for j in range(len(sum_b2)):
        if sum_a2[i] + sum_b2[j] <= k:
            tmp = [i, j]
        else:
            break

if tmp == [0, 0]:
    print(0)
else:
    print(tmp[0] + tmp[1])

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

ans=0
T=0
for i in range(N):
    T+=A[i]
    if T > K:
        T-=A[i]
        ans-=1
        break
    else:
        ans+=1
R=[]
R.append(ans)
n=ans
m=0
while(1):
    while(1):
        if m>=M: break
        T+=B[m]
        
        if T > K:
            T-=B[m]
            break
        else:
            ans+=1
            R.append(ans)
            m+=1
            
    n-=1
    if n<0: break
    T-=A[n]
    ans-=1
    

print(max(R))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
'''
N, M , lim = mi()

A = li()
B = li()

A += [10**9+1]
B += [10**9+1]
ind_a = 0 
ind_b = 0

cnt = ans = 0

while True:
    if A[ind_a] > B[ind_b]:
        if cnt + B[ind_b] <= lim:
            ans += 1
            cnt += B[ind_b]
            if ind_b != M:
                ind_b += 1
        else:
            break

    elif A[ind_a] < B[ind_b]:
        if cnt + A[ind_a] <= lim:
            ans += 1
            cnt += A[ind_a]
            if ind_a != N:
                ind_a += 1
        else:
            break

    else:
        if ind_a == N and ind_b == M:
            break
        elif ind_a == N:
            if cnt + B[ind_b] <= lim:
                ans += 1
                cnt += B[ind_b]
                if ind_b != M:
                    ind_b += 1
            else:
                break
        elif ind_b == M:
            if cnt + A[ind_a] <= lim:
                ans += 1
                cnt += A[ind_a]
                if ind_a != N:
                    ind_a += 1
            else:
                break
        else:
            if A[ind_a+1] >= B[ind_b+1]:
                if cnt + B[ind_b] <= lim:
                    ans += 1
                    cnt += B[ind_b]
                    if ind_b != M:
                        ind_b += 1
                else:
                    break
            else:
                if cnt + A[ind_a] <= lim:
                    ans += 1
                    cnt += A[ind_a]
                    if ind_a != N:
                        ind_a += 1
                else:
                    break

print(ans)
'''
N, M , lim = mi()

A = li()
B = li()

A = [0] + list(accumulate(A))
B = list(accumulate(B))
ans = 0

for i in range(N+1):
    ind = bisect.bisect_right(B, max(lim-A[i], 0))
    print(i, ind)
    if ind > 0 or lim-A[i] == 0:
        ans = max(ans, ind + i)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.append("1000000001")
b.append("1000000001")
a[n]=int(a[n])
b[m]=int(b[m])

x=0
y=0
z=0
w=0
ans=0
time=0
Ans=0
Time=0

while time<=k:
    if a[x]<=b[y]:
        time+=a[x]
        x+=1
        ans+=1
        if time>k:
            ans-=1
            
    else:
        time+=b[y]  
        y+=1
        ans+=1
        if time>k:
            ans-=1
while Time<=k:
    if a[z]<b[w]:
        Time+=a[z]
        z+=1
        Ans+=1
        if Time>k:
            Ans-=1
            
    else:
        Time+=b[w]  
        w+=1
        Ans+=1
        if Time>k:
            Ans-=1

        
print(min(ans,Ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    A = deque(A)
    B = deque(B)

    inf = 10**10
    A.append(inf)
    B.append(inf)

    ans = tot = 0

    for i in range(len(A) + len(B) + 10):
        a = A[0]
        b = B[0]

        if a < b:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()
            else:
                break

        elif a > b:
            if tot + b <= K:
                ans += 1
                tot += B.popleft()
            else:
                break

        else:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()
            else:
                break

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

from collections import deque



# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

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


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
from bisect import bisect_left as bl
def main():

    # n = int(input())
    # l = [int(j) for j in input().split()]
    
# 3 4 240
# 60 90 120
# 80 150 80 150

    # for t in range(int(input())):

    n,m,k = [int(j) for j in input().split()]
    l1 = [0]+[int(j) for j in input().split()]
    l2 = [0]+[int(j) for j in input().split()]

    # pre = [0]*n
    i = 0
    j = 0
    for i in range(1,n+1):
        l1[i] += l1[i-1]
    for i in range(1,m+1):
        l2[i] += l2[i-1]

    # print(l1, l2)
    ans =0 
    for i in range(n+1):
        if l1[i]>k: 
            break
        x = bl(l2, k-l1[i])
        if x<=m and x>0:
            if l2[x]>k-l1[i]:
                x = x-1
        ans = max(ans, x+i)
    for i in range(m+1):
        if l2[i]>k: 
            break
        x = bl(l1, k-l2[i])
        if x<=n and x>0:
            if l1[x]>k-l2[i]:
                x = x-1
        ans = max(ans, x+i)
    print(ans)






# endregion

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

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

bb = [0]*(M+1)
for i in range(1, M+1):
    bb[i] = bb[i-1]+B[i-1]

ans = 0
for i in range(N+1):
    tmp_K = K-aa[i]
    if tmp_K == 0:
        ans = max(ans, i)
    elif tmp_K < 0:
        continue

    if tmp_K <= bb[-1]:
        ans = max(ans, i+M)
    mn = 0
    mx = M
    while True:
        if mn == mx:
            if tmp_K >= bb[mn]:
                ans = max(ans, i+mn)
            break

        mid = (mn+mx//2)
        if bb[mid] <= tmp_K:
            if mn == mid:
                mn = mid+1
            else:
                mn = mid
        else:
            if mx == mid:
                mx = mid-1
            else:
                mx = mid
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = list(map(int, input().split()))
    a_books = list(map(int, input().split()))
    b_books = list(map(int, input().split()))

    minutes = 0
    count = 0
    a_idx = 0
    b_idx = 0
    if a_books[0] > k and b_books[0] > k:
        print(0)
        exit()
    elif sum(a_books) + sum(b_books) <= k:
        print(len(a_books) + len(b_books))
        exit()
    while minutes <= k:
        # print(minutes, a_idx, b_idx)

        if b_idx >= len(b_books) and a_idx >= len(a_books):
            break
        elif b_idx >= len(b_books) or (a_idx < len(a_books) and a_books[a_idx] < b_books[b_idx]):
            minutes += a_books[a_idx]
            a_idx += 1
        elif a_idx >= len(a_books) or (b_idx < len(b_books) and b_books[b_idx] < a_books[a_idx]):
            minutes += b_books[b_idx]
            b_idx += 1
        if minutes > k:
            break
        count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import inf

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

A += [float("inf")]*len(B)
B += [float("inf")]*len(A)

tot = 0
count = 0

while tot <= K:
    count += 1
    if A[0] <= B[0]:
        tot += A.pop(0)
    else:
        tot += B.pop(0)

print(count-1)

Submission status: Wrong Answer

Solution code:
import collections as deque

N, M, K = map(int, input().split())
A = deque.deque(list(map(int, input().split())))
B = deque.deque(list(map(int, input().split())))
time = 0
ans =0

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

if time >= K:
    print(ans)
else:
    if len(A) >= len(B):
        while len(A) > 0:
            time += A.popleft()
            if time <= K:
                ans += 1
            else:
                break
    else:
        while len(B) > 0:
            time += B.popleft()
            if time <= K:
                ans += 1
            else:
                break

    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

#DIV = (10**9) + 7
DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N,M,K = isRaw()
    As = isRaw()
    Bs = isRaw()
    sAs = [0]
    for a in As:
        t = a + sAs[-1]
        if t>K:
            break
        sAs.append(t)

    sBs=[0]
    for b in Bs:
        t = b + sBs[-1]
        if t>K:
            break
        sBs.append(t)

    ai = len(sAs)-1
    bi = len(sBs)-1
    while sAs[ai]+sBs[bi] > K:
        if ai==0 and bi==0:
            break
        dA = 10**9+1
        if ai!=0:
            dA = sAs[ai]-sAs[ai-1]
        dB = 10**9+1
        if bi!=0:
            dB = sBs[bi]-sBs[bi-1]
        if dA >dB:
            ai=ai-1
        else:
            bi=bi-1
    print(ai+bi)



            



main()

Submission status: Wrong Answer

Solution code:
import sys #追加
sys.setrecursionlimit(500*500)

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

time = 0
cnt = 0
ans = 0
b = []

for i in B:
    if i+time>K:
        break
    time += i
    cnt += 1
    b.append(i)

b.reverse()
# print(b)
# print(cnt)
bi = 0
for i in range(N):
    if time+A[i] <= K:
        cnt += 1
        time += A[i]
    else:
        if len(b)-1 >= bi:
            if A[i] <= b[bi]:
                time -= b[bi]-A[i]
        else:
            break
            # print("a")
            # print(time+A[i])
       
    # print(time)


print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
import bisect

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

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

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

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

    Aacc = [0]+list(accumulate(A))
    Bacc = list(accumulate(B))

    m = 0

    # print(Aacc)
    # print(Bacc)

    for i in range(N+1):
        t = Aacc[i]
        j = bisect.bisect_right(Bacc, K-t)
        # print(i, j)
        if j > 0:
            m = max(m, i+j)

    print(m)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# AtCoder
from collections import deque
N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

ans = 0
count = 0
while True:
    if len(A) != 0 and len(B) != 0:
        if A[0] > B[0]:
            t = B.popleft()
        else:
            t = A.popleft()
    elif len(A) == 0 and len(B) != 0:
        t = B.popleft()
    elif len(B) == 0 and len(A) != 0:
        t = A.popleft()

    count += t
    if 0 > K - count:
        break
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

    sumA = 0
    sumB = 0

    tmp = 0

    dA = deque(A)
    dB = deque(B)

    dsA = deque()
    dsB = deque()

    while dA:
        tmp = dA.popleft()
        if sumA + tmp < K:
            dsA.append(tmp)
            sumA += tmp
        else:
            break
    
    while dB:
        tmp = dB.popleft()
        if sumB + tmp < K:
            dsB.append(tmp)
            sumB += tmp
        else:
            break

    sumall = sumA + sumB
    lenall = len(dsA) + len(dsB)
    Atmp = 0
    Btmp = 0

    while sumall > K:
        if Atmp == 0:
            Atmp = dsA.pop()
        if Btmp == 0:
            Btmp = dsB.pop()
        if Atmp >= Btmp:
            sumall -= Atmp
            lenall -= 1
            Atmp = 0
        else:
            sumall -= Btmp
            lenall -= 1
            Btmp = 0

    print(lenall)

solve()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a_sum = a.cumsum()
b_sum = b.cumsum()

ans = 0
for i,x in enumerate(a_sum):
  if x <= k:
      j = (b_sum<=(k-x)).sum()
      if i+1+j > ans:
        ans = i+1+j
  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()))

read = 0

i = 0
j = 0

while K - A[i] > 0 or K - B[j] > 0:
    if N > 0 and M > 0:
        if A[i] <= B[j]:
            N -= 1
            read += 1
            K -= A[i]
        else:
            M -= 1
            read += 1
            K -= B[i]
    elif N <= 0 and M > 0:
        M -= 1
        read += 1
        K -= B[i]
    elif N > 0 and M <= 0:
        N -= 1
        read += 1
        K -= A[i]
    else:
        break

print(read)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A.append(float('inf'))
B.append(float('inf'))

a = A.popleft()
b = B.popleft()
ans = 0

while k > 0:
    if a <= b:
        k -= a
        a = A.popleft()
    else:
        k -= b
        b = B.popleft()
    if k >= 0:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from decimal import *

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

a = list(map(Decimal,input().split()))[::-1]
b = list(map(Decimal,input().split()))[::-1]

#print(a)
#print(b)
ans = 0
while 1:
    #print(k, a,b)
    if b == [] and a == []:
        break
    elif b == [] and a != []:
        if a[-1] <= k:
            k -= a.pop()
            ans += 1
            continue
        else:
            break
    elif a == [] and b != []:
        if b[-1] <= k:
            k -= b.pop()
            ans += 1
            continue
        else:
            break
    if a[-1] > b[-1]:
        if b[-1] <= k:
            k -= b.pop()
            ans += 1
        else:
            break
    else:
        if a[-1] <= k:
            k -= a.pop()
            ans += 1
        else:
            break



print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_list = list(map(int, input().strip().split()))
b_list = list(map(int, input().strip().split()))

out, t, i, j = 0, 0, 0, 0
s = 0
while t <= k:
    out += 1
    if i == len(a_list) and j == len(b_list):
        break
    elif i == len(a_list):
        s = b_list[j]
        j += 1
    elif j == len(b_list):
        s = a_list[i]
        i += 1
    else:
        a_n = a_list[i]
        b_n = b_list[j]
        if a_n <= b_n:
            s = a_n
            i += 1
        else:
            s = b_n
            j += 1
        t += s

print(out - 1)