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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

#print(a)
#print(b)
sum_time = 0
sum_time_a = 0
sum_time_b = 0
nn = 0
#print(b[nn])
num_books = 0
while sum_time <= k:
    if a == [] and b == []:
        num_books += 1
        break
    elif a == []:
        sum_time += b[0]
        b.pop(0)
        num_books += 1
        #print(num_books)
    elif b == []:
        sum_time += a[0]
        a.pop(0)
        num_books += 1
        #print(num_books)
    elif a[0] > 1000000000 or b[0] > 1000000000:
        num_books += 1
        break
    elif a[0] > b[0]:
        sum_time += b[0]
        b.pop(0)
        num_books += 1
        #print(num_books)
    elif a[0] < b[0]:
        sum_time += a[0]
        a.pop(0)
        num_books += 1
        #print(num_books)
    else:
        if sum_time + 2 * a[0] <= k:
            sum_time += 2 * a[0]
            a.pop(0)
            b.pop(0)
            num_books += 3
        elif sum_time + a[0] < k <= sum_time + 2 * a[0]:
            sum_time += a[0]
            num_books += 2
        else:
            num_books += 1
            break
print(num_books-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()))
s = a + b
s.sort()
ans = 0
book = 0
for i in range(len(s)):
  if ans <= k:
    if ans+s[i] <= k:
      ans += s[i]
      book += 1
    else:
      break

print(book)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
x=[int(x) for x in input().split()]
y=[int(x) for x in input().split()]
c=0
cost=0
x.sort()
y.sort()
for i in range(n):
    if i<n and cost<k and cost+x[i]<=k :
        cost+=x[i]
        c+=1
    if i<m and  cost<k and cost+y[i]<=k:
        cost+=y[i]
        c+=1
i+=1
if m>n:
    while(i<(m)):
        if cost+y[i]<=k and cost<k:
            cost+=y[i]
            c+=1
        i+=1
print(c)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

    Aq = deque()
    Bq = deque()

    for i in range(N):
        Aq.append(A[i])

    for i in range(M):
        Bq.append(B[i])

    times = 0
    read_books = 0

    while times < K:
        # print("times {} read {}".format(times, read_books))

        if not Aq and not Bq:
            break

        if not Aq:
            b = Bq.popleft()
            if b+times > K:
                break
            else:
                times += b
                read_books += 1
                continue

        if not Bq:
            a = Aq.popleft()
            if a + times > K:
                break
            else:
                times += a
                read_books += 1
                continue


        A_head = Aq.popleft()
        B_head = Bq.popleft()

        if A_head+times > K and B_head+times > K:
            break

        if A_head < B_head:
            times += A_head
            read_books += 1
            Bq.appendleft(B_head)

        else:
            times += B_head
            read_books += 1
            Aq.appendleft(A_head)

    print(read_books)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N ,M ,K = map(int, input().split())
#K = int(K/10)
#print(K)

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

m = 0
total = 0
for i in range(1, N+1):
    total += A[i-1]
    t = total
    if total > K:
        break
    mi = i
    for j in range(M):
        t += B[j]
        if t > K:
            break
        #print(total)
        mi += 1

    m = max(m, mi)


print(m)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
Alist = deque()
Blist = deque()
Alist.extend(list(map(int, input().split())))
Blist.extend(list(map(int, input().split())))

ABlist = deque()
book = 0
nm = n+m
while (len(ABlist) <= nm):
    if (len(Alist) == 0):
        ABlist.extend(Blist)
        break
    elif (len(Blist) == 0):
        ABlist.extend(Alist)
        break

    if (Alist[0] < Blist[0]):
        ABlist.append(Alist[0])
        Alist.popleft()
    else:
        ABlist.append(Blist[0])
        Blist.popleft()

while (True):
    if (len(ABlist) == 0):
        break
    if (k - ABlist[0] >= 0):
        k -= ABlist[0]
        ABlist.popleft()
        book += 1
    else:
        break
print(book)

Submission status: Wrong Answer

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

time = 0
ai = 0
bj = 0
am = 0
bm = 0

while time < K:
  if ai < len(A):
    am = A[ai]
  else:
    am = K
  if bj < len(B):
    bm = B[bj]
  else:
    bm = K

  if am < bm:
    if (time + am) > K:
      print("Aob")
      break
    else:
      time += am
      ai += 1
  else:
    if (time + bm) > K:
      break
    else:
      time += bm
      bj += 1

print(ai + bj)

Submission status: Wrong Answer

Solution code:
def go(s,b):
    count=-1
    for i in b:
        if s>=i:
           count+=1

    return count

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

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

c,d=[],[]
s=0
for i in a:
   s+=i
   c.append(s)
s=0
for i in b:
   s+=i
   d.append(s)

mx=0
for i,j in enumerate(c):
    if j<=k:
        for q,w in enumerate(d):
            if j+w<=k:
                if i+q+2>mx:
                    mx=i+q+2
for q,w in enumerate(d):
    if w<=k:
        if q+1>mx:
            mx=1+q
print(mx)

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
nowK = K
for A_idx in range(N):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
tmp_ans = ans
finish = False
for i in range(A_idx - 1, -1, -1):
    nowK += A[i]
    tmp_ans -= 1
    for j in range(B_idx, M):
        if finish or nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
        if j == M - 1:
            finish = True
    B_idx = j
    ans = max(tmp_ans, ans)
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
cost = 0
b_i = 0
if not (a[0] >= k and b[0] >= k):
  while 1:
    if ans >= n:
      if ans-n>=m:
        break
      _next = b[b_i]
      b_i += 1
    else:
      _next = a[ans]
    if (cost + _next) <= k:
      ans += 1
      cost += _next
    else:
      b_i -= 1
      break

  max_ans = ans
  if b_i == 0 or b_i == -1:
    for i in range(ans-1,-1,-1): # 2から
      ans -= 1
      cost -= a[i]
      while cost < k and b_i < m:
        ans += 1
        cost += b[b_i]
        b_i += 1
      max_ans = max(max_ans, ans)
  else:
    b_i += 1
    for i in range(n-1,-1,-1):
      ans -= 1
      cost -= a[i]
      while cost < k and b_i < m:
        ans += 1
        cost += b[b_i]
        b_i += 1
      max_ans = max(max_ans, ans)

  if a[0] <= k:
    print(max_ans)
  else:
    ans = 0
    cost = 0
    _next = 0
    while 1:
      if ans >= m:
        break
      _next = b[ans]
      if cost + _next > k:
        break
      cost += _next
      ans += 1
    print(ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split());
alist = list(map(int,input().split()));
blist = list(map(int,input().split()));
asum = [0]*(n+1);
asum[1]=alist[0];
for p in range(1,n):
    asum[p+1] = asum[p]+alist[p];
bsum = [0]*(m+1);
bsum[1]=blist[0];
for q in range(1,m):
    bsum[q+1] = bsum[q]+blist[q]
    

aa = 0;
bb = 0;
time = 0;

while True:
    if aa >= n and bb >= m:
        break;
    elif aa >= n:
        time = asum[n] + bsum[bb+1];
        if time >k:
            break;
        bb += 1;
    elif bb >= m:
        time = asum[aa+1] + bsum[m];
        if time > k:
            break;
        aa += 1
    else:
        a = asum[aa];
        b = bsum[bb];
        if a >= b:
            time = asum[aa] + bsum[bb+1]
            if time > k:
                break;
            bb += 1
        else:
            time = asum[aa+1] + bsum[bb]
            if time > k:
                break;
            aa += 1


print(aa+bb)

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

cList = [0]
dList = [0]
for a in aList:
    t = a + cList[-1]
    if t <= k:
        cList.append(a + cList[-1])
    else:
        break
for b in bList:
    t = b + dList[-1]
    if t <= k:
        dList.append(b + dList[-1])
    else:
        break
cList.pop(0)
dList.pop(0)
n = len(cList)
m = len(dList)
print(cList, dList)

if len(cList) == 0:
    print(bisect.bisect_right(dList, k))
else:
    a = 0
    for i in range(0, n+1):
        if i == n:
            lim = k
        else:
            lim = k - cList[n-1-i]
        a = max(a, n - i + bisect.bisect_right(dList, lim))
    print(a)

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 += [10**10]
B += [10**10]

ans = 0
T = 0
a, b = 0, 0
while ans <= (N+M):
    if A[a] <= B[b]:
        T += A[a]
        a += 1
    else:
        T += B[b]
        b += 1
    if T > K:
        break
    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()))
t = 0
n = 0
a = 0
b = 0

while K > t :
    if a < N and b < M :
        if A[a] <= B[b] :
            t += A[a]
            n += 1
            a += 1

        else :
            t +=B[b]
            n += 1
            b += 1
    
    elif a == N :
        while b < M :
            t += B[b]
            n += 1
            b += 1
        
        else :
            break

    else :
        while a < N :
            t += A[a]
            n += 1
            a += 1

print(n)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
from collections import deque
an= deque(map(int, input().split()))
bm= deque(map(int, input().split()))
ans =0
count = 0
while count <=k and len(an)+len(bm)>0:
    if len(an)>0 and len(bm)>0:
        if an[0] >= bm[0]:
            mini = bm.popleft()
            count += mini
            if count <=k:
                ans +=1
        else:
            mini = an.popleft()
            count += mini
            if count <= k:
                ans += 1
    elif len(bm)==0:
        mini = an.popleft()
        count += mini
        if count <= k:
            ans += 1
    elif len(an)==0:
        mini = bm.popleft()
        count += mini
        if count <= k:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m ,k = map(int,input().split())
a_list = [int(a) for a in input().split()][:n]
b_list = [int(b) for b in input().split()][:m]
time = 0
a_num = 0
b_num = 0
count = 0

while True:
    
    if (len(a_list) < a_num + 1) and (len(b_list) < b_num + 1): 
        break

    elif  (len(a_list) < a_num + 1) and (len(b_list) >= b_num + 1):
        time += b_list[b_num]      
        b_num += 1
     
    elif (len(a_list) >= a_num + 1) and (len(b_list) < b_num + 1):
        time += a_list[a_num]      
        a_num += 1
        
    elif (len(a_list) >= a_num + 1) and (len(b_list) >= b_num + 1):
        if a_list[a_num] <= b_list[b_num]:
            time += a_list[a_num]
            a_num += 1
        else:
            time += b_list[b_num]      
            b_num += 1
    
    if time <= k:
        count += 1
    else:
        break

print(count)

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()))
l = []
a.append(10**10)
b.append(10**10)

c = a.popleft()
d = b.popleft()


for i in range(n + m + 1):
    if sum(l) > k:
        ans = len(l) - 1
        print(ans)
        exit()
    if c == d == 10**10:
        print(len(l))
        exit()
    if c < d:
        l.append(c)
        c = a.popleft()
    else:
        l.append(d)
        d = b.popleft()

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
count=0
i,j=0,0
if a[i]>k:
  print(0)
  exit()
elif b[j]>k:
  print(0)
  exit()
elif sum(a)+sum(b)<=k:
  print(n+m)
  exit()
else:
  while ans<=k:
    if i > n-1:
      num=b[j]
    elif j > m-1:
      num=a[i]
    else:
      num=min(a[i],b[j])
      if num==a[i]:
        i+=1
        count+=1
        ans+=num
      else:
        j+=1
        count+=1
        ans+=num

if ans==k:
  print(count)
else:
  print(count-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()))
A.sort(reverse = True)
B.sort(reverse = True)

cnt = 0
time = 0
A_s = sum(A)
B_s = sum(B)

if A_s + B_s <= k:
  print(len(A)+len(B))
  
elif A[-1] > k and B[-1] > k:
  print(0)
  
else:
  while time <= k:
      if A[-1] >= B[-1]:
          time += B[-1]
          B.pop()
          cnt += 1
          if len(B) == 0:
              B.append(10000000000)
      else:
         time += A[-1]
         A.pop()
         cnt += 1
         if len(A) == 0:
             A.append(10000000000)
  print(cnt-1)

Submission status: Wrong Answer

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

cnt = 0

list = A + B
list = [int(s) for s in list]
list.sort()
ans = 0

min = int(int(K)/int(min(list)))
for s in range(len(list)):
    if list[s] <= int(K)-ans:
        cnt += 1
        ans += list[s]

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()))
from collections import deque
p=deque(a)
q=deque(b)

import sys
time=0
ans=0
while(1):
    if len(p)==0 and len(q)==0:
        print(ans)
        sys.exit()
    if len(p)>0 and len(q)>0:
        if p[0]>q[0]:
            time=time+q.popleft()
            if time>k:
                print(ans)
                sys.exit()
            else:
                ans=ans+1
        elif p[0]<q[0]:
            time=time+p.popleft()
            if time>k:
                print(ans)
                sys.exit()
            else:
                ans=ans+1
        elif p[0]==q[0] and len(p)==1:
            time=time+q.popleft()
            if time>k:
                print(ans)
                sys.exit()
            else:
                ans=ans+1
        elif p[0]==q[0] and len(q)==1:
            time=time+p.popleft()
            if time>k:
                print(ans)
                sys.exit()
            else:
                ans=ans+1
        else:
            if p[1]>=q[1]:
                la=q.popleft()
                if la==1000000000:
                    print(ans)
                    sys.exit()
                time=time+la
                if time>k:
                    print(ans)
                    sys.exit()
                else:
                    ans=ans+1
            else:
                la=p.popleft()
                if la==1000000000:
                    print(ans)
                    sys.exit()
                time=time+la
                if time>k:
                    print(ans)
                    sys.exit()
                else:
                    ans=ans+1
    elif len(p)==0:
        la=q.popleft()
        if la==1000000000:
            print(ans)
            sys.exit()
        time=time+la
        if time>k:
            print(ans)
            sys.exit()
        else:
            ans=ans+1
    elif len(q)==0:
        la=p.popleft()
        if la==1000000000:
            print(ans)
            sys.exit()
        time=time+la
        if time>k:
            print(ans)
            sys.exit()
        else:
            ans=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()))
 
count = 0
total = 0
idx = -1
 
for i in range(N):
  t = total + A[i]
  if t > K:
    break
  total = t
  count += 1
  idx = i
 
max_total = total
ans = count
 
for j in range(M):
  t = total + B[j]
  if t > K:
    # print(idx)
    for k in range(idx, -1, -1):
      t -= A[k]
      if t <= K:
        total = t
        count -= (idx - k - 1)
        idx = k - 1
        if max_total < total:
          max_total = total
          ans = count
  else:
    total = t
    max_total = total
    count += 1
    ans = count
 
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+=b
a.sort()
ans=0
i=0
while (k>=0 and i <(n+m)):
    k-=a[i]
    i+=1
    if k>=0:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
import numpy as np

def binary_search(lis, item):
    low = 0
    high = len(lis) - 1
    inRange = high

    while low <= high:
        mid = (low + high) //2
        guess1 = lis[mid]
        if mid < inRange:
            guess2 = lis[mid+1]
        else:
            if lis[mid] <= item:
                return len(lis)
            else:
                return len(lis)-1
        if guess1 <= item < guess2:
            return mid+1
        if guess1 > item:
            high = mid-1
        else:
            low = mid+1
    return 0

n,m,k = iim()
a = iil()
cuma = []
if a[0] <= k:
    cuma.append(a[0])
    for i in range(n-1):
        num = cuma[-1]+a[i+1]
        if num > k:
            break
        else:
            cuma.append(num)
b = iil()
cumb = []
if b[0] <= k:
    cumb.append(b[0])
    for i in range(m-1):
        num = cumb[-1]+b[i+1]
        if num > k:
            break
        else:
            cumb.append(num)
if len(cuma) > 0:
    cnt = len(cuma)
    ans = cnt+binary_search(cumb,k-cuma[-1])
    #print(k-cuma[-1],binary_search(cumb,k-cuma[-1]))
    for i,item in enumerate(cuma[::-1]):
        tmp = cnt-i
        res = k-item
        plus = binary_search(cumb,res)
        ans = max(ans,tmp+plus)
else:
    ans = binary_search(cumb,k)
print(ans)

#print(binary_search([1,2,3,4,5,6,7,8,9,10],8))

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()))
Acount = 0
Bcount = 0

for i in range(200000):

    if N != 0 and M != 0:
        if A[Acount] < B[Bcount]:
            if K >= A[Acount]:
                K = K - A[Acount]
                Acount = Acount + 1
                N = N-1
        elif A[Acount] > B[Bcount]:
            if K >= B[Bcount]:
                K = K - B[Bcount]
                Bcount = Bcount +1
                M = M-1
    elif N == 0 and M != 0:
        if K >= B[Bcount]:
                K = K - B[Bcount]
                Bcount = Bcount +1
                M = M-1
    elif N != 0 and M == 0:
        if K >= A[Acount]:
            K = K - A[Acount]
            Acount = Acount +1
            N = N-1
                

print(Acount + Bcount)

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

suma = [ -1 for i in range(n) ]
sumb = [ -1 for i in range(m) ]
suma[0] = a[0]
sumb[0] = b[0]
nn = n
mm = m
for i in range(1,n):
  suma[i] = suma[i - 1] + a[i]
  if suma[i] > k:
    nn = i
    break
for i in range(1,m):
  sumb[i] = sumb[i - 1] + b[i]
  if sumb[i] > k:
    mm = i
    break

c = 0
t = 0
cc = 0
for i in range(nn):
  if suma[i] <= k:
    t = suma[i]
    c = i + 1
  for j in range(mm):
    tt = t + sumb[j]
    if tt <= k:
      cc = max(cc,c + j + 1)

print(cc)

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

if(sum(a)+sum(b)<=k):
    print(len(a)+len(b))
    exit()

if(n<m):
    for i in range(m-n):
        a.append(10**10)
if(n>m):
    for i in range(n-m):
        b.append(10**10)

#print(a)
#print(b)
time=0
i=0
j=0
count=0

while(True):
    
    if(i>len(a)-1):
        time+=b[j]
        count+=1
        j+=1
        
    if(j>len(b)-1):
        time+=a[i]
        count+=1
        i+=1
    
    
    if(time>k):
        break
    
    if(a[i]<b[j]):
        time+=a[i]
        count+=1
        i+=1
    elif(a[i]>b[j]):
        time+=b[j]
        count+=1
        j+=1
    else:
        ii=i
        jj=j
        while(True):
            if(a[ii]<b[ii]):
                time+=a[i]
                count+=1
                i+=1
                break
            elif(a[ii]>b[jj]):
                time+=b[j]
                count+=1
                j+=1
                break
            else:
                ii+=1
                jj+=1
                if(ii>len(a)-1):
                    time+=b[j]
                    count+=1
                    j+=1
                    break
                if(jj>len(b)-1):
                    time+=a[i]
                    count+=1
                    i+=1
                    break

        

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

books = sorted(A+B)

cnt=0
max = N+M-1

while K >= 0:

  K-=books[cnt]
  cnt+=1
  
  if cnt > max:
    cnt = N+M+1
    break
  
print(cnt-1)

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import deque

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


count = 0
time = 0
#もし先にどっちかの玉が尽きた時の問題。
for i in range(10**6):
    #本が尽きていない。
    if len(A) != 0 and len(B) != 0:

        if A[0] < B[0]:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()

        elif A[0] > B[0]:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
        else:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
    else:
        #どっかの本が尽きている。
        if len(A) == 0 and len(B) != 0:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
        elif len(A) != 0 and len(B) == 0:
            time = time +A[0]
            if time <= K:
                count = count + 1
                A.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
        elif len(A) == 0 and len(B) == 0:
            print(count)
            sys.exit()
               


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()))
An = []
Bn = []
for n in range(N):
    if n == 0:
        An.append(A[n])
    else:
        An.append(An[n-1]+A[n])
    if An[n] > K:
        break
N = n+1

for n in range(M):
    if n == 0:
        Bn.append(B[n])
    else:
        Bn.append(Bn[n-1]+B[n])
    if Bn[n] > K:
        break

M = n+1

old = 0

for n in range(N):
    if An[n] > K:
        break

for nn in reversed(range(n+1)):
    for m in range(M):
        if Bn[m] + An[nn] <= K:
            if old < m+nn+2:
                old = m+nn+2


print(old)

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()))
time = 0
count = 0

if k < a[0] or k < b[0]:
    print(0)
    exit()

def read(books, minutes):
    global time
    global count
    time += minutes
    count += 1
    books.pop(0)

while time <= k:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        read(b, b[0])
    elif len(b) == 0:
        read(a, a[0])
    else:
        if a[0] <= b[0]:
            read(a, a[0])
        else:
            read(b, b[0])

if len(a) == 0 and len(b) == 0:
    print(count)
else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

a = 0
b = 0
t_sum = 0
ans = 0


while True:
    if a < N and b < M:
        if A[a] <= B[b]:
            t_sum += A[a]
            a += 1
        else:
            t_sum += B[b]
            b += 1
    elif a >= N and b >= M:
        break
    elif a >= N:
        t_sum += B[b]
        b += 1
    elif b >= M:
        t_sum += A[a]
        a += 1
#    print(a,b)
#    print(t_sum)
    if t_sum > K:
        break
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
deskA = list(map(int,input().split()))
deskB = list(map(int,input().split()))
bookcount = 0
time = 0
while time <= k:
    if deskA == [] and deskB == []:
        bookcount += 1
        break
    elif deskB == []:
        t = deskA.pop(0)
    elif deskA == []:
        t = deskB.pop(0)
    elif deskA <= deskB:
        t = deskA.pop(0)
    elif deskA > deskB:
        t = deskB.pop(0)
    time += t
    bookcount += 1

print(bookcount-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()))
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
        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:
n, m, k = map(int, input().split())
time = 0
res = 0
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ai = 0
bi = 0
 
aa = a[ai]
bb = b[bi]
 
while True:
    if aa == bb:
        if len(a) > ai + 1:
            if len(b) > bi + 1:
                if a[ai + 1] < b[bi + 1]:
                    time += a[ai]
                    ai + 1
                else:
                    time += b[ai]
                    bi += 1
            else:
                time += a[ai]
                ai += 1
        else:
            time += b[ai]
            bi += 1
    
    elif aa < bb:
        time += aa
        ai += 1
        if len(a) > ai:
            aa = a[ai]
        else:
            aa = 10000000000
    else:
        time += bb
        bi += 1
        if len(b) > bi:
            bb = b[bi]
        else:
            bb = 10000000000
    
    if time <= k:
        res += 1
    else:
        break
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()))
A.append(2*10**10)
B.append(2*10**10)
A.append(2*10**10)
B.append(2*10**10)
 
ans = 0
t = 0
ia, ib = 0, 0
while t < K and (ia < N or ib < M):
    if A[ia] + A[ia+1] <= B[ib] + B[ib+1]:
        if t + A[ia] <= K:
            t += A[ia]
            ans += 1
            ia += 1
        else: break
    else:
        if t + B[ib] <= K:
            t += B[ib]
            ans += 1
            ib += 1
        else: break
    print(t, ia, ib, ans)
 
print(ans)

Submission status: Wrong Answer

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

b1=[int(x) for x in input().split()]
b2=[int(x) for x in input().split()]

b=b1+b2
b.sort()
if sum(b1)+sum(b2)==k:
    print(n+m)
else:
    sum=0
    for i in range(len(b)):
        sum=sum+b[i]
        if sum >= k:
            break
    print(i)

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
ans2 = 0
for i in range(n+m):
    if 0 != len(a) and 0 != len(b):
        if a[0] <= b[0]:
            if k >= ans + a[0]:
                ans += a[0]
                ans2 += 1
            else:
                break
            a.remove(a[0])
        else:
            if k >= ans + b[0]:
                ans += b[0]
                ans2 += 1
            else:
                break
            b.remove(b[0])
    else:
        if len(a) == 0 and len(b) == 0:
            break
        elif len(a) == 0:
            if k >= ans + b[0]:
                ans += b[0]
                ans2 += 1
            else:
                break
            b.remove(b[0])
        else:
            if k >= ans + a[0]:
                ans += a[0]
                ans2 += 1
            else:
                break
            a.remove(a[0])

print(ans2)