Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n,m,k = IL()
    a = list(accumulate(IL()))
    b = list(accumulate(IL()))
    ans = 0
    for i,item in enumerate(a):
        if k<item:  break
        c = i+1
        for j in b:
            if item+j<=k:
                c += 1
            else:
                break
        ans = max(ans,c)
    print(ans)
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

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

target = [A_i_list[0], B_i_list[0]]

## とりあえずAだけのパターンをつくり、そこから
## 一個ずつ引いていく

## Aだけ
counter_A = 0
counter_B = 0
sum_A_list = []
sum_B_list = []
sum_A = 0
sum_B = 0

while True:
    sum_A = sum_A + A_i_list[counter_A]
    if sum_A > K:
        break
    sum_A_list.append(sum_A)
    counter_A = counter_A + 1
    if counter_A == N:
        break
# print(sum_A_list)

while True:
    sum_B = sum_B + B_i_list[counter_B]
    if sum_B > K:
        break
    sum_B_list.append(sum_B)
    counter_B = counter_B + 1
    if counter_B == M:
        break
# print(sum_B_list)

result = []
if len(sum_A_list) == 0:
    result_final = len(sum_B_list)
elif len(sum_B_list) == 0:
    result_final = len(sum_A_list)
else:
    for i, sum_A_target in enumerate(sum_A_list):
        # print("==========")
        # print("i:"+ str(i))
        sum_temp = sum_A_target
        for j in range(len(sum_B_list)):
            # print("j:"+ str(j))
            if sum_temp + sum_B_list[j] > K:
                result.append(i+j+1)
                # print(result)
                break
            if j == len(sum_B_list)-1:
                result.append(i+j+2)
                print(result)
                break
    result_final = max(result)
print(result_final)

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

t = k
i = 0
asum = [0]* (n+1)
bsum = [0]* (m+1)
suma = 0
sumb = 0

for  i in range(n):
    suma += a[i]
    asum[i+1]= suma


for  i in range(m):
    sumb += b[i]
    bsum[i+1] = sumb

count = 1
ans = 0

for i in range(n+1):
    if ans -i<0:
        break
    for j in range(ans-i,m+1,1):
        if asum[i] + bsum[j]<=k and i+j>ans:
            ans=i+j

print(min(ans,m+n))

Submission status: Wrong Answer

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

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

books = sorted(A+B)

cnt=0
max = N+M-1

while True:
  
  K-=books[cnt]
  if K < 0:
    break
  elif cnt >= max:
    cnt+=1
    break    
  else:
    cnt+=1
  
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
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)

if a[0]>k and b[0]>k:
  print(0)
else:
  if sum(a)+sum(b)<=k:
    print(n+m+1)
  else:
    ans=0
    time=0
    for i in range(n+m+1):
      ans += 1    
      if a[0]<=b[0]:
        time+=a.pop(0)
      else:
        time+=b.pop(0)
      
      if time>k:
        break
    print(ans-1)

Submission status: Wrong Answer

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

for x in range(n):
  sum1=0
  ans1=0
 
  sum1=sum(a[0:x])
  if sum1>k:
    break
  else:
  	ans1+=1
  for y in range(m):
    
      
    sum1+=b[y]
    if sum1>k:
      break
    else:
      ans1+=1
      if ans1>ans:
         ans=ans1
        
print(ans)

Submission status: Wrong Answer

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

a_idx = N - 1
b_idx = M - 1
cnt = N + M
summation = sum(A_list) + sum(B_list)
if summation <= K:
  print(N + M)
  exit()
else:
  while True:
    # print(cnt, summation)
    if a_idx >= 0 and b_idx >= 0:
      if A_list[a_idx] >= B_list[b_idx]:
        summation -= A_list[a_idx]
        cnt -= 1
        a_idx -= 1
      else:
        summation -= B_list[b_idx]
        cnt -= 1
        b_idx -= 1
    elif a_idx < 0 and b_idx >= 0:
      summation -= B_list[b_idx]
      cnt -= 1
      b_idx -= 1
    elif a_idx >= 0 and b_idx < 0:
      summation -= A_list[a_idx]
      cnt -= 1
      a_idx -= 1
      
    if a_idx == -1 and b_idx == -1:
      break
      
    if summation <= K:
      cnt += 1
      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()))

i = 0
j = 0
ans = 0
while i < n and j < m and ((k - min(a[i], b[j])) >= 0):
    if a[i] <= b[j]:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1

    ans+=1

while i < n and ((k - a[i]) >= 0):
    k -= a[i]
    i+=1
    ans+=1

while j < m and ((k - b[j]) >= 0):
    k -= b[j]
    j+=1
    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()))

n = 0
m = 0
ans = 0
while K >= 0:
  if K == 0:
    print(ans)
    exit()
  if n < N and m < M:
    if A[n] >= B[m]:
      K = K - B[m]
      m += 1
    elif A[n] < B[m]:
      K = K - A[n]
      n += 1
  elif n < N and m >= M:
    K = K - A[n]
    n += 1
  elif n >= N and m < M:
    K = K - B[m]
    m += 1
  else:
    print(N + M)
    exit()

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

Submission status: Wrong Answer

Solution code:
M, N, K = map(int, input().split())
A = map(int,input().split())
B = map(int,input().split())
C = list(A) + list(B)
H = 0
N = 0
if min(C) < K:
    while H < K:
        min_hour = min(C)
        H += min_hour
        if H <= K:
            N += 1
        C.remove(min_hour)
print(N)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
i = 0
j = 0
ans = 0
time = 0

while 1:
    if i < N and j < M:
        if A[i] < B[j]:
            ans += 1
            time += A[i]
            i += 1
        elif A[i] > B[i]:
            ans += 1
            time += B[j]
            j += 1
        else:
            if i < N-1 and j < M-1:
                if A[i+1] <= B[j+1]:
                    ans += 1
                    time += A[i]
                    i += 1
                else:
                    ans += 1
                    time += B[j]
                    j += 1
            elif i < N-1:
                ans += 1
                time += A[i]
                i += 1
            else:
                ans += 1
                time += B[j]
                j += 1
    elif i < N:
        ans += 1
        time += A[i]
        i += 1
    elif j < M:
        ans += 1
        time += B[j]
        j += 1
    else:
        break

    if time > K:
        ans -= 1
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n, m, k = map(int, input().split())
A = defaultdict(lambda: {"score": 0, "time": 10**10})
B = defaultdict(lambda: {"score": 0, "time": 10**10})
*tA, = map(int, input().split())
*tB, = map(int, input().split())
for i, a in enumerate(tA):
    A[i]["score"] = 1
    A[i]["time"] = a
for i, b in enumerate(tB):
    B[i]["score"] = 1
    B[i]["time"] = b
tmp = 0
cnt = 0
i, j = 0, 0
while tmp + A[i]["time"] <= k or tmp + B[j]["time"] <= k:
    if A[i]["time"] <= B[j]["time"]:
        tmp += A[i]["time"]
        cnt += A[i]["score"]
        i += 1
    else:
        tmp += B[j]["time"]
        cnt += B[j]["score"]
        j += 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 = 0
aa = 0
bb = 0


for i in range(n):
    if k - a[i] < 0:
        break
    else:
        k -= a[i]
        aa += 1
ans = aa
#print(ans)

for i in range(m):
    if k - b[i] >= 0:
        k -= b[i]
        bb += 1
        if ans < aa + bb:
            ans = aa + bb
    else:
        while aa > 0:
            aa -= 1

            k += a[aa]
            if k - b[i] >= 0:
                k -= b[i]
                bb += 1
                break

        if ans < aa + bb:
            ans = aa + bb
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_N = list(map(int, input().split()))
B_M = list(map(int, input().split()))
 
A_ind = 0
B_ind = 0
count = K
ans = 0
 
for i in range(N+M): 
  if A_N[0] < B_M[0]:
    if count >= A_N[0]:
      count -= A_N.pop(0)
      ans += 1
      if len(A_N) == 0:
        A_N.append(1000000001)
  else:
    if count >= B_M[0]:
      count -= B_M.pop(0)
      ans += 1
      if len(B_M) == 0:
        B_M.append(1000000001)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools as it
input = sys.stdin.readline

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

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))

max = 0
for i in range(len(AS)):
    a = AS[i]
    for j in range(len(BS)):
        b = BS[j]
        if a + b > K:
            break
        if max < i + j + 2:
            max = i + j + 2

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()))
i=j=0
ans=0
h=k
s1=sum(a)
s2=sum(b)
while k>=0:
    if i<len(a) and j<len(b):
        if a[i]<=b[j]:
            k=k-a[i]
            i=i+1
        elif a[i]>b[j]:
            k=k-b[j]
            j=j+1
    else:
        if i<len(a):
            k=k-a[i]
            i=i+1
        elif j<len(b):
            k=k-b[j]
            j=j+1
        else:
            break
    if k>=0:
        ans=ans+1
a.reverse()
b.reverse()
ans1=len(a)
ans2=len(b)
for i in a:
    if s1<=h:
        break
    else:
        s1=s1-i
        ans1=ans1-1
for i in b:
    if s2<=h:
        break
    else:
        s2=s2-i
        ans2=ans2-1
print(max(max(ans1,ans2),ans))

Submission status: Wrong Answer

Solution code:

def main():
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().strip().split()))
    B = list(map(int, input().strip().split()))
    
    x = 0
    y = 0
    time = 0
    books = 0

    while time <= K:
        if x < N and y < M:
            if A[x] <= B[y]:
                if time + A[x] <= K:
                    time = time + A[x]
                    x = x + 1
                    books = books + 1
                else:
                    return books
            else:
                if time + B[y] <= K:
                    time = time + B[y]
                    y = y + 1
                    books = books + 1
                else:
                    return books
        elif x < N and y >= M:
            if time + A[x] <= K:
                time = time + A[x]
                x = x + 1
                books = books + 1
            else:
                return books
        elif x >= N and y < M:
            if time + B[y] <= K:
                time = time + B[y]
                y = y + 1
                books = books + 1
            else:
                return books
        else:
            return books

def main_2():
    books = main()
    print(books)

main_2()

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
c = 0
if sum(a) + sum(b) <= k:
    print(n+m)
    quit()
for i in range(min(n, m)):
    if t + a[i]> k:
        print(c)
        quit()
    t += a[i]
    c += 1
    if t + b[i]> k:
        print(c)
        quit()
    t += b[i]
    c += 1
    
if t < k:
    if max(n, m) == n:
        d = a
        e = b
    else:
        d = b
        e = a
    for i in range (len(e), len(d)-1):
        if t + d[i] > k:
            print(c)
            quit()
        t += d[i]
        c += 1
    print(c)
else:
    print(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()))

time = 0
book = 0

while time < k:
    if len(a) == 0:
        time += b.pop(0)
        book += 1
    elif len(b) == 0:
        time += a.pop(0)
        book += 1
    else:
        if a <= b:
            if a[0]+time < k:
                time += a.pop(0)
                book += 1
            else:
                break
        else:
            if b[0]+time < k:
                time += b.pop(0)
                book += 1
            else:
                break
        
print(book)

Submission status: Wrong Answer

Solution code:
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
#print(a, b)
time = k
for i in range(400010):
    if time > 0:
        if not a and not(not b):
            time -= b[0]
            b.popleft()
            ans += 1
               # print(a, b, time)
        elif not a and not b:
               # print(a, b, time)
                break
        elif not b and not(not a):
            time -= a[0]
            a.popleft()
            ans += 1
            #print(a, b, time)
        elif not(not a) and not(not b):
            if a[0] <= b[0]:
                time -= a[0]
                a.popleft()
                ans += 1
                #print(a, b, time)
            else:
                time -= b[0]
                b.popleft()
                ans += 1
                #print(a, b, time)
if time < 0:
    print(ans - 1)
else:
    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()))

r0=0
rr = 0
t0=0
i = 0
j = 0
flag = 0

while t0<=K:
    t0 = t0 + A[i]
    if t0<=K:
        r0 = r0 + 1
        if i==N-1:
            break
        i = i + 1

if t0>K:
    t0 = t0 - A[i]

while t0<=K:
    t0 = t0 + B[j]
    if t0<=K:
        r0 = r0 + 1
        if j==M-1:
            flag = 1
            break
        j = j + 1

if t0>K:
    t0 = t0 - B[j]

rr = r0
Kk = K
tk = t0
rk = r0

for k in range(i+1):
    if flag == 1:
        break
    Kk = Kk + A[i-k] - tk
    tk = 0
    ik = 0
    rk = rk - 1
    while tk<=Kk:
        tk = tk + B[j]
        if tk<=Kk:
            rk = rk + 1
            if j == M-1:
                flag = 1
                break
            j = j+1
    rr = max(rk,rr)


print(rr)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int,input().split())
    from collections import deque
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    if sum(a)+sum(b) <= k:
        print(m+n)
        return 0
    if a[0] > k and b[0] > k:
        print(0)
        return 0
    ad = deque(a)
    bd = deque(b)
    cnt = 0
    inf = 10**18
    p = inf
    q = inf
    while True:
        if p == inf and ad:
            p = ad.popleft()
        if q == inf and bd:
            q = bd.popleft()
        if p < q:
            k -= p
            p = inf
        else:
            k -= q
            q = inf
        if k >= 0:
            cnt += 1
        if k < 0:
            break
    print(cnt)              


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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

b_list = list(map(int, input().split()))
b_list  = b_list[::-1]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
    
list_ = list_ + a_list + b_list

left = 0
right = len(list_)+1
while abs(left-right)>1:
  mid = (left+right) // 2
  if sum(list_[:mid])<=k:
    left = mid
  else:
    right = mid

print(len(list_[:left]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    CNT = 0
    As = sum(A)
    Bs = sum(B)
    ans = 0
    for i in range(N):
        k = K
        Sa = sum(A[0:i+1])
        if k >= Sa:
            k -= Sa
        else:
            continue
        CNT += i+1
        for j in range(M):
            if k < 0:
                break
            if k >= B[j]:
                k -= B[j]
                CNT += 1
            else:
                continue
        ans = max(ans, CNT)
        CNT = 0
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
time = 0
ans = 0
if (sum(A) + sum(B)) <= k:
    print(len(A)+len(B))
    exit() 
while len(A) != 0 or len(B) != 0:
    if len(A) == 0:
        time += B[0]
        if time <= k:
            ans += 1
            B.popleft()
        else:
            print(ans)
            exit()
    elif len(B) == 0:
        time += A[0]
        if time <= k:
            ans += 1
            A.popleft()
        else:
            print(ans)
            exit()
    else:
        if A[0] <= B[0]:
            time += A[0]
            if time <= k:
                ans += 1
                A.popleft()
            else:
                print(ans)
                exit()
        else:
            time += B[0]
            if time <= k:
                ans += 1
                B.popleft()
            else:
                print(ans)
                exit()
print(ans)

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()))
    
    if a[0] > K and b[0] > K:
        return 0

    a2=[0]
    for i in a:
        if a2[-1] >= K:
            break 
        a2.append(a2[-1]+i)
    a2 = a2[:-1]

    b2=[0]
    for i in b:
        if b2[-1] >= K:
            break 
        b2.append(b2[-1]+i)
    b2 = b2[:-1]

    at = 0
    a_val = 0
    ab = len(a2)
    bt = 0
    b_val = 0
    bb = len(b2)
    mm = 0
    while True :
        val = 0
        if len(a2[at:]) >= len(b2[bt:]):
            val = a[at]
            a_val += val
            at += 1             
        else:
            val = b[bt]
            b_val += val
            bt += 1
        mm += val
        
        while a2[ab-1] - a_val > (K - mm) and at < ab:
            ab -= 1
        a2 = a2[:ab]
        while b2[bb-1] - b_val > (K - mm) and bt < bb:
            bb -= 1
        b2 = b2[:bb]
        if len(a2[at:]) == 0 and len(b2[bt:]) == 0:
            break
    return at + bt

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = input().split()
np_a=np.array(a, dtype='int64')
b = input().split()
np_b=np.array(b, dtype='int64')

ia=0
ib=0
time=0
hon=n+m
for i in range(0,n+m):
  if (ia == n): 
    time+=np_b[ib]
    ib+=1
  elif (ib == m): 
    time+=np_a[ia] 
    ia+=1
  elif (ia < n or ib < m): 
    if (np_a[ia] <= np_b[ib]):
      time+=np_a[ia]
      ia+=1
    else:
      time+=np_b[ib]
      ib+=1
    
  if (time > k): 
    hon=i
    break

print (hon)

Submission status: Wrong Answer

Solution code:
str1 = input().strip().split()
str_a = input().strip().split()
str_b = input().strip().split()

a_kazu = int(str1[0])
b_kazu = int(str1[1])
jikan_ = int(str1[2])

str_a_count = 0
str_b_count = 0
count = 0

for num in range(a_kazu + b_kazu):
    try:
      if int(str_a[str_a_count]) < int(str_b[str_b_count]):
        jikan_ = jikan_ - int(str_a[str_a_count])
        str_a_count = str_a_count + 1
        count = count + 1
        if jikan_ < 0:
          break
      else:
        jikan_ = jikan_ - int(str_b[str_b_count])
        str_b_count = str_b_count + 1
        count = count + 1
        if jikan_ < 0:
          break
    except:
      try:
        jikan_ = jikan_ - int(str_a[str_a_count])
        str_a_count = str_a_count + 1
        count = count + 1
        if jikan_ < 0:
          break
      except:
        jikan_ = jikan_ - int(str_b[str_b_count])
        str_b_count = str_b_count + 1
        count = count + 1
        if jikan_ < 0:
          break
if count == (a_kazu + b_kazu):
  print(count)
else:
  print(count - 1)

Submission status: Wrong Answer

Solution code:
import sys
a, b, n = map(int, input().split())
alis = list(map(int, input().split()))
blis = list(map(int, input().split()))
alis.append(sys.maxsize)
blis.append(sys.maxsize)

count = 0
time = 0

ac = 0
bc = 0
while time <= n:
    time += min(alis[ac], blis[bc])
    count += 1
    if alis[ac] <= blis[bc]:
        ac += 1
    else:
        bc +=1

print(count-1)

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_cum = list(itertools.accumulate(A))

idx = 0
cnt = 0
tmp = 0
post_idx = 0
for i in range(m):
    b = B[i]
    idx = bisect.bisect_left(A,b,lo=idx+1)
    A.insert(idx,b)
print(A)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M,K=map(int,input().split())
A=deque(map(int,input().split()))
B=deque(map(int,input().split()))
if sum(A)+sum(B)<=K:
    print(len(A)+len(B))
else:
    ans=0
    count=0
    while count<K and len(A)!=0 and len(B)!=0:
        m=min(A[0],B[0])
        count+=m
        if m==A[0]:
            A.popleft()
        else:
            B.popleft()
        ans+=1
        if count>K:
            ans-=1
    if count<K and len(A)==0:
        while count<K:
            m=B[0]
            count+=m
            B.popleft()
            ans+=1
    if count<K and len(B)==0:
        while count<K:
            m=A[0]
            count+=m
            A.popleft()
            ans+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
a = input().split(" ")
N = int(a[0])
M = int(a[1])
K = int(a[2])
Ai = input().split(" ")
Bi = input().split(" ")
Ai = [int(s) for s in Ai]
Bi = [int(s) for s in Bi]
time_ = int(K)
time0 = 0
acount = 0
bcount = 0

for i in range(10000000000000000):
    try:
        time0 += Ai[i]
        if time0 > time_:
            time0 -= Ai[i]
            break
        acount += 1
    except IndexError:
        break
atime = time0
time0 = 0
for i in range(10000000000000000):
    try:
        time0 += Bi[i]
        if time0 > time_:
            time0 -= Bi[i]
            break
        bcount += 1
    except IndexError:
        break
btime = time0
allc = bcount
if bcount > acount:
    hic = bcount
else:
    hic = acount
# AiからBiに移す
ci = 0
for i in range(acount):

    try:
        while time0 + Ai[i + ci] <= time_:
            time0 += Ai[i+ci]
            allc += 1
            ci += 1
            if hic < allc:
                hic = allc
    except IndexError:
        pass
    try:
        time0 -= Bi[bcount - 1]
        bcount -= 1
        allc -= 1
    except IndexError:
        break
    try:
        while time0 + Ai[i+ci] <= time_:
            time0 += Ai[i+ci]
            allc += 1
            ci += 1
            if hic < allc:
                hic = allc
    except IndexError:
        break
print(hic)

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())))
sum = 0
count = 0
while True:
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        sum += B.popleft()
        count += 1
    elif len(B) == 0:
        sum += A.popleft()
        count += 1
    elif A[0] < B[0] and A[0]+sum <= K:
        sum += A.popleft()
        count += 1
    elif A[0] > B[0] and B[0]+sum <= K:
        sum += B.popleft()
        count += 1
    else:
        break

print(count)

Submission status: Wrong Answer

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

rui_A = [0 for _ in range(N)]
rui_B = [0 for _ in range(M)]

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

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

max_book = 0
for i in range(len(rui_A)):
    if rui_A[i] <= K:
        nokori = K - rui_A[i]
        B_posi = bisect.bisect_right(rui_B,nokori)
        if max_book < B_posi + i:
            max_book = B_posi + i + 1
print(max_book)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

time = 0
i_a = 0; i_b = 0
ans = 0

q = deque()
qa = deque(A); qb = deque(B)
a = qa.popleft(); b = qb.popleft()

while qa or qb:
    if a >= b:
        q.append(b)
        if qb:
            b = qb.popleft()
        else:
            b = 1000000001
    elif a < b:
        q.append(a)
        if qa:
            a = qa.popleft()
        else:
            a = 1000000001

q.append(min(a, b))    
    
for i in range(len(q)):
    time += q.popleft()
    if time > K:
        break
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
def ss(s,a):
    nn=len(a)
    for i in range(nn):
        if a[i]>s:return i
    return nn
n,m,s=map(int, stdin.readline().split());M=10**9+2
dn=list(map(int, stdin.readline().split()))#+[M]
dm=list(map(int, stdin.readline().split()))#+[M]
pn=[dn[0]];pm=[dm[0]]
for v in dn[1:]:
    pn+=[pn[-1]+v]
for v in dm[1:]:
    pm+=[pm[-1]+v]
p=ss(s,pn)
q=ss(0 if p-1<0 else s-pn[p-1],pm)
pp=ss(s,pm)
qq=ss(0 if pp-1<0 else s-pm[pp-1],pn)
print(max(p+q,pp+qq))

'''cn=0;cm=0;cs=0
for v in dn:
    cs+=v
    if cn>=n-1 or cs>s:
        f=1;cs-=v
        for v1 in dm:
            cs+=v1
            if cs>s:
                f=0
                break
            cn+=1
        if f==0:break
    #print(v)
    cn+=1
cs=0
for v in dm:
    cs+=v
    if cm>=m-1 or cs>s:
        f=1;cs-=v
        for v1 in dn:
            cs+=v1
            if cs>s:
                f=0
                break
            cm+=1
        if f==0:break
    cm+=1
print(max(cn,cm))'''

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int,input().split())
    from collections import deque
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    if sum(a)+sum(b) <= k:
        print(m+n)
        return 0
    if a[0] > k and b[0] > k:
        print(0)
        return 0
    ad = deque(a)
    bd = deque(b)
    cnt = 0
    inf = 10**18
    p = inf
    q = inf
    while True:
        if p == inf and ad:
            p = ad.popleft()
        if q == inf and bd:
            q = bd.popleft()
        if p < q:
            k -= p
            p = inf
        else:
            k -= q
            q = inf
        if k > 0:
            cnt += 1
        if k <= 0:
            break
    print(cnt)              


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from decimal import Decimal

def main():
  M, N, K = map(Decimal, input().split())
  A = list(map(Decimal, input().split()))
  B = list(map(Decimal, input().split()))
  spent_time = Decimal(0)
  count = 0
  AB = A + B
  AB.sort()
  
  while(True):
    if count == M + N:
      break
    temp = AB[count]
    #print(temp, spent_time)
    if spent_time + temp > K:
      break
    spent_time = spent_time + temp
    count += 1
  
  #print('----')
  #print(spent_time)
  print(count)
  
main()

Submission status: Wrong Answer

Solution code:
import sys
intMaxValue = sys.maxsize
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum = 0
j = 0
l = 0
count = 0

for i in range(10 ** 9 * 10 ** 9):


    if A == [] and B == []:
        break

    if A == [] or B == []:
        if A == []:
            if B[0] + sum <= K and intMaxValue > B[0] + sum:
                sum += B[0]
                B.pop(0)
                count += 1
                # j += 1
            else:
                break
        elif B == []:
            if A[0] + sum <= K and intMaxValue > A[0] + sum:
                sum += A[0]
                A.pop(0)
                count += 1
                # j += 1
            else:
                break
    else:
        if A[0] > B[0]:
            if B[0] + sum <= K and intMaxValue > B[0] + sum:
                sum += B[0]
                B.pop(0)
                count += 1
                # j += 1
            else:
                break
        else:
            if A[0] + sum <= K and intMaxValue > A[0] + sum:
                sum += A[0]
                A.pop(0)
                count += 1
                # l += 1
            else:
                break
        

print(count)