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:
# coding: utf-8
# Your code here!

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

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

AL = []
BL = []
a = 0
for i in A:
    a += i
    AL.append(a)
a = 0
for i in B:
    a += i
    BL.append(a)

#print(AL)
#print(BL)

a = 0
for i in range(len(AL)):
    if AL[i] > k:
        a = i
        break
else:
    a = len(AL)

b = 0
for i in range(len(BL)):
    if BL[i] > k:
        b = i
        break
else:
    b = len(BL)

#print(a,b)

m = 0

while True:
    t = k-AL[a-1]
    for i in reversed(range(b)):
        if t-BL[i]>=0:
            if m < a + i +1:
                m = a + i +1
            break
    a += -1
    if a < 0 or a+b<=m:
        break
print(m)

Submission status: Wrong Answer

Solution code:


import sys
import math
import itertools
import collections

def solve(N,M,K,A,B):
    flagA = False
    flagB = False
    total = 0
    ans = 0
    while True:
        if flagA and flagB:
            break
        elif flagA:
            target =[B.pop(0)]
        elif flagB:
            target = [A.pop(0)]
        else:
            target = [A[0],B[0]]
        if (K - total) >= min(target):
            total += min(target)
            ans += 1
            if len(target) == 2:
                A.pop(0) if A[0] == min(target) else B.pop(0)
            
            if len(A) == 0:
                flagA = True
            if len(B) == 0:
                flagB = True
        else:
            break
    return ans





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

if __name__ == "__main__":
    main()


    # total = 0
    # counter = 0
    # accumA = [A.pop(0)]
    # accumB = [B.pop(0)]
    # for a,b in zip(A,B):
    #     accumA.append(accumA[-1] + a)
    #     accumB.append(accumB[-1] + b)
    # ans = 0

Submission status: Wrong Answer

Solution code:

def resolve():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))[::-1]
    B = list(map(int, input().split()))[::-1]

    ans = 0
    time = 0
    for _ in range(N+M):
        a = 1<<60
        b = 1<<60
        min_t = 0
        if A:
            a = A[-1]
        if B:
            b = B[-1]
        if a < b:
            min_t += a
            A.pop()
        else:
            min_t += b
            B.pop()

        if time+min_t > K:
            break
        time += min_t
        ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=0
b=0
ans=0
for i in range(N+M):
  if a<N and b<M:
    if A[a]<B[b]:
      K-=A[a]
      a+=1
    elif A[a]>B[b]:
      K-=B[b]
      b+=1
    elif A[a]==B[b]:
      for i in range(1,200000):
        if a<N-i and b<M-i:
          if A[a+i]<B[b+i]:
            K-=A[a]
            a+=1
            break
          elif A[a+i]>B[b+i]:
            K-=B[b]
            b+=1
            break
        elif a<N-i and b>=M-i:
          if A[a+i]<B[-1]:
            K-=A[a]
            a+=1
            break
          elif A[a+i]>B[-1]:
            K-=B[b]
            b+=1
            break
        elif b<M-i and a>=N-i:
          if B[b+i]<A[-1]:
            K-=B[b]
            b+=1
            break
          elif B[b+i]>A[-1]:
            K-=A[a]
            a+=1
            break
        elif a>=N-i and b>=M-i:
          K-=A[a]
          a+=1
          break
  elif a<N:
    K-=A[a]
    a+=1
  elif b<M:
    K-=B[b]
    b+=1
  else:
    break
  if K>=0:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _, _, k = _ia()
    a = list(_ia()) + [k+1]
    b = list(_ia()) + [k+1]
    s = 0
    cnt = 0
    i, j = 0, 0
    while s < k:
        ai, bj = a[i], b[j]
        if ai < bj:
            s += ai
            i += 1
        else:
            s += bj
            j += 1
        if s <= k:
            cnt += 1

    return cnt


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

Submission status: Wrong Answer

Solution code:
[N,M,K]=list(map(int, input().split()))
alist=list(map(int, input().split()))
blist=list(map(int, input().split()))
alist.sort()
blist.sort()
time=0
ans=-1
ai=0
bi=0
while time<=K:
    ans+=1
    if ai==len(alist) and bi==len(blist):
        break
    elif ai==len(alist):
        time+=blist[bi]
        bi+=1
    elif bi==len(blist):
        time+=alist[ai]
        ai+=1
    elif alist[ai]>blist[bi]:
        time+=blist[bi]
        bi+=1
    else:
        time+=alist[ai]
        ai+=1
    #print(time,ai,bi)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
n,m,s=map(int, stdin.readline().split())
dn=list(map(int, stdin.readline().split()))+[s+1]
dm=list(map(int, stdin.readline().split()))+[s+1]
cn=0;cm=0;cs=0
for v in dn:
    cs+=v
    if 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 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(cn,cm)
print(max(cn,cm))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

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

ans = 0
while True:
    if len(A) > 0 and len(B) > 0:
        temp = min(A[0],B[0])
        if (temp > K):
            break
        if A[0] > B[0]:
            K = K - B[0]
            if K < 0: 
                break
            B = B[1:]
            ans += 1
        elif B[0] > A[0]:
            K = K - A[0]
            if K < 0: 
                break
            A = A[1:]
            ans += 1
        elif B[0] == A[0]:
            if len(A) > 1 and len(B) > 1:
                if A[1] > B[1]:
                    K = K - B[0]
                    if K < 0: 
                        break
                    B = B[1:]
                    ans += 1
                elif B[1] > A[1]:
                    K = K - A[0]
                    if K < 0: 
                        break
                    A = A[1:]
                    ans += 1           
            elif len(A) == 1 and len(B) > 1:
                if A[0] > B[1]:
                    K = K - B[0]
                    if K < 0: 
                        break
                    B = B[1:]
                    ans += 1
                elif B[1] > A[0]:
                    K = K - A[0]
                    if K < 0: 
                        break
                    A = A[1:]
                    ans += 1
            elif len(B) == 1 and len(A) > 1:
                if B[0] > A[1]:
                    K = K - A[0]
                    if K < 0: 
                        break
                    A = A[1:]
                    ans += 1
                elif A[1] > B[0]:
                    K = K - B[0]
                    if K < 0: 
                        break
                    A = B[1:]
                    ans += 1  
    elif len(A) == 0 and len(B) > 0:
        K = K - B[0]
        if K < 0: 
                break
        B = B[1:]
        ans += 1
    elif len(B) == 0 and len(A) > 0:
        K = K - A[0]
        if K < 0: 
                break
        A = A[1:]
        ans += 1
    elif len(A) == 0 and len(B) == 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
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()]
aima = 0
bima = 0
ans = 0
for i in range(N+M):
    if aima == N:
        aa = 10**11
    else:
        aa = a[aima]
    if bima == M:
        bb = 10**11
    else:
        bb = b[bima]
    if aa <= bb:
        if K - aa < 0:
            break
        else:
            ans += 1
            K -= aa
            aima += 1
    elif bb < aa:
        if K - bb < 0:
            break
        else:
            ans += 1
            K -= bb
            bima += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
import sys
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if k<a[0] and k<b[0]:
    print(0)
    sys.exit()
coa=0
cob=0
co=0
c=0
i=0
j=0
x=0
y=0
while 1:
    if i==1 and j==1:
        print(co)
        break
    elif i==1:
        c=b[cob]
        x=1
        
    elif j==1:
        c=a[coa]
        y=1
        
    else:
        c=min(a[coa],b[cob])
    if x==1:
        k-=b[cob]
        cob+=1
        co+=1
        if cob==m:
            j=1
    elif y==1:
        
        k-=a[coa]
        coa+=1
        co+=1
        if coa==n:
            i=1
    else:

        if c==a[coa]:
            k-=a[coa]
            coa+=1
            co+=1
            if coa==n:
                i=1
            
        else:
            k-=b[cob]
            cob+=1
            co+=1
            if cob==m:
                j=1

    if k<0:
        print(co-1)
        break

Submission status: Wrong Answer

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

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

i=0
j=0
c=0
p=0
l=l[::-1]
x=x[::-1]

while len(l) or len(x):

    if len(l)>0 and len(x)>0:

        z=min(l[-1],x[-1])
        if c+z<=k:
            c+=z
            if z==l[-1]:
                l.pop()
            else:
                x.pop()
            p+=1
        else:
            break
    elif len(l)>0 and len(x)==0:

        if c+l[-1]<=k:
            p+=1
            l.pop()
        else:
            break
    elif len(l)==0 and len(x)>0:

        if c+x[-1]<=k:
            p+=1
            x.pop()
        else:
            break
    elif len(l)==0 and len(x)==0:
      break
print(p)

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(M):
    A.append(B[i])
    
A.sort()

ans = 0
count = 0

for i in range(N+M):
    if K >= A[i]:
        K = K - A[i]
        count += 1
        i += 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.append(10**9 + 1)
b.append(10**9 + 1)

ai = 0
bi = 0
t = 0
c = 0
ab = []
while ai != n or bi != m:
    if a[ai] > b[bi]:
        ab.append(b[bi])
        bi += 1
    else:
        ab.append(a[ai])
        ai += 1

for i in range(n + m):
    t += ab[i]
    if t > k:
        break
    else:
        c += 1

print(c)

Submission status: Wrong Answer

Solution code:
a = [input() for l in range(0,3)]
a1 = [int(p) for p in a[0].split()]
a2 = [int(p) for p in a[1].split()]
a3 = [int(p) for p in a[2].split()]
a4 = a2 + a3
b = sorted(a4)

c = 0
for i in range(0,len(b)):
    c = c + b[i]

if c == a1[2]:
    print(len(b))
else:
    s = 0
    t = 0
    while s <= a1[2] and t < len(b):
        s = s + b[t]
        t = t + 1
    print(t-1)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
time = 0
ans = 0
a = 0
b = 0
while K >= time:
    if len(A) == a and len(B) == b:
        ans += 1
        break
    elif len(A) > a and len(B) > b:
        if A[a] > B[b]:
            time += B[b]
            b += 1
            ans += 1
        else:
            time += A[a]
            a += 1
            ans += 1
    elif len(A) <= a:
        time += B[b]
        b += 1
        ans += 1
    else:
        time += A[a]
        a += 1
        ans += 1

print(ans-1)

Submission status: Wrong Answer

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

flg = True
n_cnt = 0
m_cnt = 0
doku_cnt = 0

while flg:
    if n_cnt != n and m_cnt != m:
        if x >= a[n_cnt] or x >= b[m_cnt]:
            if a[n_cnt] <= b[m_cnt] or n_cnt >= n:
                x = x - a[n_cnt]
                n_cnt += 1
                doku_cnt += 1
            else:
                x = x - b[m_cnt]
                m_cnt += 1
                doku_cnt += 1
        else:
            flg = False
    else:
        if m == m_cnt and n == n_cnt:
            flg = False
        elif n == n_cnt:
            x = x - b[m_cnt]
            m_cnt += 1
            doku_cnt += 1
        elif m == m_cnt:
            x = x - a[n_cnt]
            n_cnt += 1
            doku_cnt += 1

print(doku_cnt)

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 = 0
ans = 0

for i in range(N+M): 
  if A_N[A_ind] < B_M[B_ind]:
    if count + A_N[A_ind] <= K:
      count += A_N[A_ind]
      ans += 1
      if A_ind == N-1:
        A_N[A_ind] = 1000000001
      else:
        A_ind += 1
    else:
      break
  elif A_N[A_ind] >= B_M[B_ind]:
    if count + B_M[B_ind] <= K:
      count += B_M[B_ind]
      ans += 1
      if B_ind == M-1:
        B_M[B_ind] = 1000000001
      else:
        B_ind += 1
    else:
      break

print(ans)

Submission status: Wrong Answer

Solution code:
n, m , k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

total = 0
res = 0
i_a = 0
i_b = 0
while total < k:
  if i_a >= n and i_b >= m:
    break
  if i_a >= n:
    total += b[i_b]
    i_b +=1
  elif i_b >= m:
    total += a[i_a]
    i_a += 1
  else:
    if a[i_a] < b[i_b]:
      total += a[i_a]
      i_a += 1
    elif a[i_a] > b[i_b]:
      total += b[i_b]
      i_b += 1
    else:
      if i_a == n-1:
        total += a[i_a]
        i_a += 1
      elif i_b == m-1:
        total += b[i_b]
        i_b += 1
      elif a[i_a+1] < b[i_b+1]:
        total += a[i_a]
        i_a += 1
      else:
        total += b[i_b]
        i_b += 1
  if total <= k:
    res += 1
print(res)

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()))
maxcnt = 0
for i in range(n):
  asum = sum(A[0:i+1])
  if k < asum:
    break
  elif k == asum:
    maxcnt = max(maxcnt, i+1)
    break
  currentcnt = i+1
  zantime = k - asum
  for j in range(m):
    if zantime < B[j]:
      break
    currentcnt += 1
    if zantime == B[j]:
      break
    zantime -= B[j]
  maxcnt = max(maxcnt, currentcnt)
print(maxcnt)

Submission status: Wrong Answer

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m,k=map(int, readline().rstrip().split())
    aa=list(map(int, readline().rstrip().split()))
    bb=list(map(int, readline().rstrip().split()))
    dp=0
    asum=[0]*n
    bsum=[0]*m
    memo=[0]*n
    asum[0]=aa[0]
    bsum[0]=bb[0]
    memo[0]=k-aa[0]
    mp=n-1
    ans=0
    for i in range(1,n):
        asum[i]=(aa[i]+aa[i-1])
        memo[0]=k-asum[i]
    for i in range(1,m):
        bsum[i]=(bb[i]+bb[i-1])
    for i in range(m):
        x = bsum[i]
        while mp>=0:
            if asum[mp]+x <= k:
                break
            else:
                mp-=1
            if mp==-1:
                break
        if asum[mp]+x <= k:
            ans = max(i+1 + mp+1,ans)

    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Wrong Answer

Solution code:
def aaa():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = []
    for i,j in zip(a,b):
        c.append(i)
        c.append(j)
    c = sorted(c)
    d = 0
    e = 0
    for i in c:
        if i+e < k:
            e += i
            d += 1
        else:
            return d
    return n + m
aaa()

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

import numpy as np

A.extend(B)

A.sort()

res = np.cumsum(A)
r = list(res)

cnt = 0
for i in r:
    if i < K:
        cnt += 1
    else:
        break

print(cnt)

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())))
t = 0
for i in range(len(A)+len(B)+1):
    if len(A) == 0 and len(B) == 0:
        break
    if len(A) == 0:
        t += B.popleft()
    elif len(B) == 0:
        t += A.popleft()
    elif A[0] < B[0]:
        t += A.popleft()
    else:
        t += B.popleft()
    if t > K:
        break
print(i)

Submission status: Wrong Answer

Solution code:
A, B, t = map(int, input().split())

desk_A = list(map(int, input().split()))
desk_B = list(map(int, input().split()))

i = 0
j = 0
count = 0

while((i < A and j < B) and t > 0):
    flag = 1
    if desk_A[i] < desk_B[j]:
        if t >= desk_A[i]:
            t -= desk_A[i]
            i += 1
            flag = 0
    
    else:
        if t >= desk_B[j]:
            t -= desk_B[j]
            j += 1
            flag = 0
    if flag == 1:
        break
    
    count += 1
  
while(i < A and t > 0):
    if t >= desk_A[i]:
        t -= desk_A[i]
        i += 1
        count += 1
    else:
        break
  
while(j < B and t > 0):
    if t >= desk_B[j]:
        t -= desk_B[j]
        j += 1
        count += 1
    else:
        break


print(count)

Submission status: Wrong Answer

Solution code:
MAX=10**9+1
def main(n, m, k, a_n, b_n):
    a_n.append(MAX)
    b_n.append(MAX)

    r = 0
    a = 0
    b = 0
    for _ in range(n+m):
        a_v = a_n[a]
        b_v = b_n[b]

        if a_v == float('inf') and b_v == float('inf'):
            return r

        if a_v < b_v:
            k -= a_n[a]
            a += 1
        else:
            k -= b_n[b]
            b += 1

        if k >= 0:
            r += 1

        if k <= 0:
            return r
    return r

if __name__ == "__main__":
    n, m, k = map(int, input().split())
    a_n = [int(x) for x in input().split()]
    b_n = [int(x) for x in input().split()]
    print(main(n, m, k, a_n, b_n))

Submission status: Wrong Answer

Solution code:
def problem():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 0
    t = 0
    n = -1 * n
    m = -1 * m

    while k > t:
        if n == 0 and m == 0:
            return ans
        if n == 0 and m != 0:
            t += b[m]
            ans += 1
            m += 1
        if n != 0 and m == 0:
            t += a[n]
            ans += 1
            n += 1
        if n != 0 and m != 0:
            if a[n] >= b[m]:
                t += b[m]
                ans += 1
                m += 1
            else:
                t += a[n]
                ans += 1
                n += 1
        if k < t:
            return ans-1
    return ans

problem()

Submission status: Wrong Answer

Solution code:
from collections import deque
from bisect import bisect

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
R_B = deque()
R_B.append(0)
i = 0
while i < M:
  R_B.append(R_B[-1]+B[i])
  i += 1 
R_B = list(R_B)
ans = 0
i = 0
while i < N and K >= A[i]:
  K -= A[i]
  idx = bisect(R_B, K)
  ans = max(ans, i+idx)
  R_B = R_B[:idx+1]
  i += 1
print(ans)

Submission status: Wrong Answer

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

sum_alist=[0]
for i in range(N):
  sum_alist.append(sum_alist[-1]+alist[i])
#print(sum_alist)

sum_blist=[0]
for i in range(M):
  sum_blist.append(sum_blist[-1]+blist[i])
#print(sum_blist)

limit_a=bisect.bisect(sum_alist,K)
#print(limit_a)

limit_b=bisect.bisect(sum_blist,K)
#print(limit_b)

answer=0
for i in reversed(range(1,limit_a)):
  a_sum=sum_alist[i]
  b_sum=K-a_sum
  pos_b=bisect.bisect(sum_blist,b_sum)
  #print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
  answer=max(answer,i+pos_b-1)
  
print(answer)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]

time = 0
cnt = 0

def check(LIST, time):
  time += LIST[0]
  del LIST[0]
  if LIST == []:
    LIST.append(10**10)
  return time
    
while True:
  if As[0] < Bs[0]:
    time = check(As, time)
  else:
    time = check(Bs, time)
  if time > K:
    break
  cnt+=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
m=0
i=len(a)-1
j=len(b)-1
if a[i]>k and b[j]>k:
    ans=0
    print(ans)
    exit()
while m<=k:
    if i>=0 and j>=0:
        if a[i]>=b[j]:
            ans+=1
            m+=b[j]
            j=j-1
        else:
            ans+=1
            m+=a[i]
            i=i-1
    elif i<=-1 and j>=0:
        ans+=1
        m+=b[j]
        j=j-1
    elif i>=0 and j<=-1:
        ans+=1
        m+=a[i]
        i=i-1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

time = 0
ans = 0
book = max(n, m)
INF = float('inf')

if n >= m:
    b += [INF]*(n-m+1)
    a.append(INF)
else:
    a += [INF]*(m-n+1)
    b.append(INF)

a = collections.deque(a)
b = collections.deque(b)



while time + min(a[0], b[0]) <= k:
    ans += 1
    time += min(a[0], b[0])

    if a[0] > b[0]:
        b.popleft()
    elif a[0] < b[0]:
        a.popleft()
    else:
        for i in range(1, min(len(a), len(b))):
            if a[i] > b[i]:
                b.popleft()
                break
            elif a[i] < b[i]:
                a.popleft()
                break

print(ans)

Submission status: Wrong Answer

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

a.append(pow(10,10))
b.append(pow(10,10))

ans = 0
ai = 0
bi = 0

while True:
  t = 0
  if a[ai] > b[bi]:
    t = b[bi]
    bi += 1
  else:
    t = a[ai]
    ai += 1
  if k >= t:
    k -= t
    ans += 1
  else:
    break

print(str(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
import copy
N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
counter = 0
ans = 0
a = A.popleft()
b = B.popleft()
while counter < K:
    ans += 1
    if a >= b:
        counter += b
        if not B:
            b = 0
            break
        b = B.popleft()
    else:
        counter += a
        if not A:
            a = 0
            break
        a = A.popleft()
if counter > K:
    print(ans - 1)
else:
    if a == 0:
        A = copy.deepcopy(B)
        a = b
    while counter < K:
        ans += 1
        counter += a
        if not A:
            if counter <= K:
                ans += 1
            break
        a = A.popleft()
    print(ans - 1)

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M,K=nm()
INF=10**18
A=nl()
B=nl()
A.append(INF)
B.append(INF)

ans=0
while(1):
    if(A[0]<=B[0]):
        K-=A[0]
        A.pop(0)
    else:
        K-=B[0]
        B.pop(0)
    if(K<0):
        print(ans)
        sys.exit(0)
    ans+=1

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

A.append(1000000000)
B.append(1000000000)

time = 0
ans = 0

i, j = 0, 0
if A[0]>K and B[0]>K:
    print(0)
    sys.exit()
else:
    for _ in range(len(A)+len(B)-2):
        if A[i] <=B[j]:
            time += A[i]
            if time <=K:
                ans += 1
                i += 1
            else:
                break
        elif A[i] >= B[j]:
            time += B[j]
            if time <= K:
                ans += 1
                j += 1
            else:
                break
        print(i,j,time)
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()))
count = 0
numa = 0
numb = 0
while True:
    if numa < len(A) and numb < len(B):#リストの番号をどちらも指定できる
        if A[numa] <= B[numb] and count + A[numa] <= K:#AがB以下
            count += A[numa]
            numa += 1
        elif A[numa] > B[numb] and count + B[numb] <= K:#AがBより大きい
            count += B[numb]
            numb +=1
        else:#これ以上本を取り除けない
            break
    
    elif numa >= len(A) and numb < len(B):#Aだけのリストが終了
        if count + B[numb]<=K:
            count += B[numb]
            numb += 1
        else:
            break
    elif numa < len(A) and numb >= len(B):#Bだけのリストが終了
        if count + A[numa]<=K:
            count += A[numa]
            numa += 1
        else:
            break
    else:#リストのどちらも終了
        break

print(numa+numb)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for i in range(len(A)):
  A[i] = int(A[i])
for i in range(len(B)):
  B[i] = int(B[i])
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count = 0
for i in range(N):
  if A_cumsum[i] > K:
    break
  for j in range(M):
    if A_cumsum[i] + B_cumsum[j] <= K and max_count < A_cumsum[i] + B_cumsum[j]:
      max_count = i + j + 2
    else:
      break
print(max_count)

Submission status: Wrong Answer

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

AB = A+B
AB = sorted(AB)
#print(A,B,AB)

count=0
jikan=0
for i in range(len(AB)):
    jikan+=AB[i]
    if jikan<=K:
        count+=1
    else:
        break
print(count)

Submission status: Wrong Answer

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

A=[]
B=[]

for a in A_in:
    A.append(int(a))
    
for b in B_in:
    B.append(int(b))

time = 0
cnt = 0

while cnt < len(A) + len(B):
    
    if len(A) > 0 and len(B) > 0:
        if A[0] > B[0]:
            time += B[0]
            B.pop(0)
        else:
            time += A[0]
            A.pop(0)
            
        if time <= K:
            cnt += 1
            
    elif len(A) == 0 and len(B) > 0:
        time += B[0]
        B.pop(0)
        if time <= K:
            cnt += 1
            
    elif len(B) == 0 and len(A) > 0:
        time += A[0]
        A.pop(0)
        if time <= K:
            cnt += 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()))
X = sorted(A + B)
time = 0
cnt = 0
for i in range(len(X)):
    if K < X[i] + time:
        break
    else:
        time += X[i]
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

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

new_a=[]
new_b=[]
add=0
add_a=0
for i in a:
    if add+i<=k:
        new_a.append(i)
        add_a+=i
    add+=i

add=0
add_b=0
for j in b:
    if add+j<=k:
        new_b.append(j)
        add_b+=j
    add+=j

#print(new_a,new_b)

add=0
if len(new_a)>len(new_b):
    k-=add_a
    count=len(new_a)
    for i in new_b:
        if add+i<k:
            count+=1
elif len(new_b)>len(new_a):
    k-=add_b
    count=len(new_b)
    for i in new_a:
        if add+i<k:
            count+=1
else:
    if add_a < add_b:
        k-=add_a
        count=len(new_a)
        for i in new_b:
            if add+i<k:
                count+=1
    else:
        k-=add_b
        count=len(new_b)
        for i in new_a:
            if add+i<k:
                count+=1

print(count)