Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.append(10**9+1)
B.append(10**9+1)
a = 0
b = 0
ans = 0
t = 0
while t < K :
    if A[a] < B[b]:
        if t+A[a] <= K:
            ans += 1
            t += A[a]
            a += 1
        else:
            break
    else:
        if t+B[b] <= K:
            ans += 1
            t += B[b]
            b += 1
        else:
            break
ans2 = 0
a = 0
b = 0
t = 0
while t < K :
    if A[a] > B[b]:
        if t+A[a] <= K:
            ans2 += 1
            t += A[a]
            a += 1
        else:
            break
    else:
        if t+B[b] <= K:
            ans2 += 1
            t += B[b]
            b += 1
        else:
            break
print(max(ans,ans2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#import numpy as np
import re
import math
from collections import defaultdict,deque,Counter
from fractions import Fraction
import bisect
import itertools
from itertools import accumulate
from copy import deepcopy
import heapq
import random
import time
import os
import sys
from functools import lru_cache,reduce
readline=sys.stdin.readline
sys.setrecursionlimit(100000)
alp="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Set():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(bool)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        if not self.find(x):
            heapq.heappush(self.heap,x)
            self.dic[x]=True
            self.size+=1

    def remove(self,x):
        if self.find(x):
            self.dic[x]=False
            self.size-=1

    def find(self,x):
        return self.dic[x]
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==False:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class multiset():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(int)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        heapq.heappush(self.heap,x)
        self.dic[x]+=1
        self.size+=1

    def remove(self,x):
        if self.dic[x]>0:
            self.dic[x]-=1
            self.size-=1
    
    def count(self,x):
        return self.dic[x]

    def find(self,x):
        return self.dic[x]>0
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==0:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):print("yes" if b else "no")
def Yn(b):print("Yes" if b else "No")
def YN(b):print("YES" if b else "NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(b,t,f):return t if b else f
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def inputint(row=1): 
    if row==1:
        ret=list(map(int,input().split()))
        if len(ret)==1:ret=ret[0]
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=int(input())
    return ret
def inputfloat(row=1): 
    if row==1:
        ret=list(map(float,input().split()))
        if len(ret)==1:ret=ret[0]
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=float(input())
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])#[cost,x]
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def zipsort(*args):
    ziplist=sorted(zip(*args))
    for a in range(len(args)):
        for b in range(len(ziplist)):
            args[a][b]=ziplist[b][a]
def zipreverse(*args):
    ziplist=list(zip(*args))
    rev=[]
    for a in range(len(ziplist)-1,-1,-1):
        rev.append(ziplist[a])
    for a in range(len(args)):
        for b in range(len(rev)):
            args[a][b]=rev[b][a]

######################################################################################################
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
for a in range(100):
    A.append(10**20)
    B.append(10**20)
A.reverse()
B.reverse()
ans=0
while K>=0:
    if A[-1]<B[-1]:
        K-=A.pop()
    else:
        K-=B.pop()
    if K>=0:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

idx_a = 0
idx_b = 0
tot = 0
cnt = 0

while True:
    if len(A) > 0:
        acc_a = A.pop()
    else:
        acc_a = sys.maxsize
    if len(B) > 0:
        acc_b = B.pop()
    else:
        acc_b = sys.maxsize
    acc = min(acc_a, acc_b)
    if tot + acc <= K:
        cnt += 1
    else:
        break

    tot += min(acc_a, acc_b)
    if acc_a <= acc_b:
        B.append(acc_b)
    else:
        A.append(acc_a)

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

time = 0
count = 0
i = 0
j = 0

while time <= k:
    if i >= n and j >= m:
        break
    if i == n:
        mi = b[j]
        j += 1
    elif j == m:
        mi = a[i]
        i += 1
    elif a[i] < b[j]:
        mi = a[i]
        i += 1
    else:
        mi = b[j]
        j += 1
    if (time + mi) <= k:
        count += 1
        time += mi
    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()))
result = 0
count = 0
while True:
  if not a and not b:
    print(count)
    break
  if result > k:
    print(count-1)
    break
  if not a:
    result += b.pop()
    count += 1
  elif not b:
    result += a.pop()
    count += 1
  elif a[0] < b[0]:
    result += a.pop(0)
    count += 1
  else:
    result += b.pop(0)
    count += 1

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

ans = 0
m = 0
for i in A:
  m += i
  if m > K:
    break
  ans += 1

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

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

if ans == 0:
  t = 0
else:
  t = C[ans - 1]

k = ans
n = ans
for i in range(M):
  m = D[i]
  if m > K: break
  while m + t > K:
    n -= 1
    if n <= -1:
      t = 0
      break
    t = C[n - 1]
  ans = max(ans, i + 1 + n)

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m,k=nii()
a=lnii()
b=lnii()

t=0
ans=0

while t<=k:
  if a:
    a_c=a[0]
  else:
    a_c=10**18
  if b:
    b_c=b[0]
  else:
    b_c=10**18

  if a_c<=b_c:
    ans+=1
    t+=a_c
    if a:
      del a[0]
  else:
    ans+=1
    t+=b_c
    if b:
      del b[0]

if ans==0:
  print(0)
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


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


def instr():
    s = input()
    return(list(s[:len(s)]))


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


n, m, t = invr()
a = inlist()
b = inlist()
MAX = 1000000001
i = j = 0
read = 0
count = 0
while read < t:
    ax = bx = MAX
    if i < n:
        ax = a[i]
    if j < m:
        bx = b[j]
    min_t = min(ax, bx)
    if read + min_t <= t:
        count += 1
        read += min_t
        if ax == min_t:
            i += 1
        else:
            j += 1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import collections

rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, m, k = rm()
a = collections.deque(rl())
b = collections.deque(rl())

time = 0
cnt = 0
while len(a) != 0 and len(b) != 0:
  if a[0] > b[0]:
    t = b.popleft()
  else:
    t = a.popleft()
  time += t
  if time <= k:
    cnt += 1
  else:
    break
if len(a) == 0:
  for t in b:
    time += t
    if time <= k:
      cnt += 1
elif len(b) == 0:
  for t in a:
    time += t
    if time <= k:
      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()))
cost = 0
ind_a = 0
ind_b = 0
num_book = -1
while cost <= K:
    num_book += 1
    if ind_a == N and ind_b == M:
        break
    if ind_a >= N:
        cost += B[ind_b]
        ind_b += 1
    elif ind_b >= M:
        cost += A[ind_a]
        ind_a += 1
    elif A[ind_a] > B[ind_b]:
        cost += B[ind_b]
        ind_b += 1
    else:
        cost += A[ind_a]
        ind_a += 1
print(num_book)

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)

lst = []

i = 0
j = 0
while(i < N or j < M):
    if A[i] > B[j]:
        lst.append(B[j])
        j += 1
    else:
        lst.append(A[i])
        i += 1
            
ans = 0
for i in lst:
    K -= i
    ans += 1
    if K < 0:
        ans -= 1
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=0
b=0
t=0
while a+b<N+M:
    if a==N:
        if t+B[b]<=K:
            t+=B[b]
            b+=1
        else:
            break
    elif b==M:
        if t+A[a]<=K:
            t+=A[a]
            a+=1
        else:
            break
    else:
        if t+min(A[a],B[b])<=K:
            if A[a]<B[b]:
                t+=A[a]
                a+=1
            else:
                t+=B[b]
                b+=1
        else:
            break
print(a+b)

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, t, i, j = 0, 0, 0, 0
while True:
    if i > N-1 and j <= M-1:
        t += B[j]
        j += 1
        if t <= K:
            ans += 1
        else:
            break
    elif j > M-1 and i <= N-1:
            t += A[i]
            i += 1
            if t <= K:
                ans += 1
            else:
                break
    elif i > N-1 and j > M-1:
        break
    else:
        if A[i] <= B[j]:
            t += A[i]
            i += 1
            if t <= K:
                ans += 1
            else:
                break 
        else:
            t += B[j]
            j += 1
            if t <= K:
                ans += 1
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
p1, p2 = 0, 0
count = 0
track = 0
while p1 < len(arr1) or p2 < len(arr2):
    if p1 == len(arr1) or p2 == len(arr2):
        if p1 == len(arr1):
            track += arr2[p2]
            p2 += 1
        else:
            track += arr1[p1]
            p1 += 1
    elif arr1[p1] <= arr2[p2]:
        track += arr1[p1]
        p1 += 1
    elif arr2[p2] < arr1[p1]:
        track += arr2[p2]
        p2 += 1
    if track > k:
        break
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

a.append(10**9+1)
b.append(10**9+1)
time = 0
count = -1

while time <= k:
  if a[0] <= b[0]:
    time += a.popleft()
  else:
    time += b.popleft()
    
  count += 1

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()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
count = 0
A.append(10**9+1)
B.append(10**9+1)
A.append(10**9+1)
B.append(10**9+1)

i = 0
j = 0
while K >= 0:
    if A[i] == B[j]:
        if A[i+1] <= B[j+1]:
            count += 1
            K -= A[i]
            i += 1
        else:
            count += 1
            K -= B[j]
            j += 1
    elif A[i] < B[j]:
        count += 1
        K -= A[i]
        i += 1
    else:
        count += 1
        K -= B[j]
        j += 1

print(count-1)

Submission status: Wrong Answer

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

n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
cnt = 0
idx = 0
res = [0]

na, nb = [a[0]], [b[0]]

for x in range(1, n):
    na.append(na[-1] + a[x])

for x in range(1, m):
    nb.append(nb[-1] + b[x])

for x in range(n - 1, -1, -1):
    if na[x] > k:
        continue

    while True:
        if idx + 1 < m and na[x] + nb[idx + 1] <= k:
            if idx + 1 >= m:
                break
            
            idx += 1
        else:
            break

    res.append(x + idx + 2)

print(max(res))

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,B,ans,fa,fb=0,0,0,0,0
while k>0:
  if fa==0 and fb==0:
    if a[A]<b[B]:
      k-=a[A]
      A+=1
      if A>=n:
        fa+=1
    else:
      k-=b[B]
      B+=1
      if B>=m:
        fb+=1
    ans+=1
  elif fa==0:
    k-=a[A]
    A+=1
    ans+=1
    if A>=n:
      fa+=1
  elif fb==0:
    k-=b[B]
    B+=1
    ans+=1
    if B>=m:
      fa+=1
  else:
    ans+=2
    break
print(ans-1)

Submission status: Wrong Answer

Solution code:
from collections import *
import sys
from bisect import *
input=sys.stdin.readline
from math import *
t=1
while(t):
    t-=1
    n,m,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    i,j=0,0
    r=0
    while(1):
        ff=0
        if(i<n and j<m):
            if(a[i]<b[j] and k>=a[i]):
                r+=1
                ff=1
                k-=a[i]
                i+=1
            elif(k>=b[j] and b[j]<a[i]):
                j+=1
                ff=1
                r+=1
                k-=b[j-1]
            elif(k>=a[i]):
                if(i==n-1):
                    k-=b[j]
                    j+=1
                    r+=1
                    ff=1
                elif(j==m-1):
                    k-=a[i]
                    j+=1
                    r+=1
                    ff=1
                else:
                    if(a[i+1]>=b[j+1]):
                        k-=b[j]
                        j+=1
                        r+=1
                        ff=1
                    else:
                        k-=a[i]
                        i+=1
                        r+=1
                        ff=1
        elif(i>=n and j<m):
            if(k>=b[j]):
                r+=1
                k-=b[j]
                j+=1
                ff=1
        elif(j>=m and i<n):
            if(k>=a[i]):
                r+=1
                k-=a[i]
                i+=1
                ff=1
        else:
            break
        #print(k,ff,i,j)
        if(ff==0):
            break
    print(r)

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 itertools
A = list(itertools.accumulate(A))
B = list(itertools.accumulate(B))
ans=0
ak,bk=0,0
while ak+bk<K:
  if len(A)>0:
    a=A[0]
  else:
    a=10**10
  if len(B)>0:
    b=B[0]
  else:
    b=10**10
    
  if a<b:
    ak=a
    A.pop(0)
    ans+=1
  elif b<a:
    bk=b
    B.pop(0)
    ans+=1
  else:
    if a==10**10:
      break
    else:
      ak=a
      A.pop(0)
      ans+=1
  if ak+bk>K:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m, k = i_map()
    a_list = i_list()
    b_list = i_list()

    read_time = 0

    for i in range(n+m):
        if read_time > k:
            print(i-1)
            exit()
        if len(a_list) == 0:
            a = INF
        else:
            a = a_list[0]
        if len(b_list) == 0:
            b = INF
        else:
            b = b_list[0]
        if a <= b:
            read_time += a
            a_list.pop(0)
            # print(i,read_time)
        else:
            read_time += b
            b_list.pop(0)
            # print(i,read_time)

    print(n+m)
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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

time = 0
count = 0

while time <= K:
    if len(A) > 0 and len(B) > 0:
        break
    a = 1000000001
    b = 1000000001
    if len(A) > 0:
        a = A.pop()
    if len(B) > 0:
        b = B.pop()

    if a < b:
        B.append(b)
        time += a
    else:
        A.append(a)
        time += b
    count += 1

print(count - 1)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = list(map(int, input().split())) + [10**12]
B = list(map(int, input().split())) + [10**12]
ia = 0
ib = 0
t = 0
while True:
    if ia == n and ib == m:
        break  # ぜんぶ使い切り
    if k < t + A[ia] and k < t + B[ib]:
        break  # 使えるものがない
    if A[ia] <= B[ib]:
        t += A[ia]
        ia += 1
    else:
        t += B[ib]
        ib += 1
ans = ia + ib
print(ans)

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()))
ad = deque(a)
ad.append(float('inf'))
bd = deque(b)
bd.append(float('inf'))
count = 0
while True:
    k = k - min(ad[0],bd[0])
    if k < 0:
        break
    if ad[0] > bd[0]:
        bd.popleft()
    else:
        ad.popleft()
    count += 1
print(count)

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
    b = K-A[i]
    if b <= 0:
        break
    j = bisect.bisect_right(B, b)
    if ans < (i+1+j):
        ans = i+1+j
print(ans)

Submission status: Wrong Answer

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

AA = list(reversed(A))
BB = list(reversed(B))

rest = K
ans = 0
while len(AA) != 0 and len(BB) != 0:

    if AA[-1] < BB[-1]:
        rest -= AA[-1]
        last = AA.pop()
        # print("READ:", last, ans)
    else:
        rest -= BB[-1]
        last = BB.pop()
        # print("READ:", last, ans)

    ans += 1
    if rest <= 0:
        break
if len(AA) > 0:
    while rest > 0:
        rest -= AA[-1]
        AA.pop()
        ans += 1

if len(BB) > 0:
    while rest > 0:
        rest -= BB[-1]
        BB.pop()
        ans += 1

# print(rest)
if rest == 0:
    print(ans)
elif rest < 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()))
count = 0
time = 0
while time <= K:
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) != 0 and (len(B) == 0 or A[0] <= B[0]):
        if time + A[0] > K:
            break
        count += 1
        time += A[0]
        A = A[1:]
    elif len(B) != 0 and (len(A) == 0 or A[0] > B[0]):
        if time + B[0] > K:
            break
        count += 1
        time += B[0]
        B = B[1:]
print(count)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()
a = na()
b = na()
aa = [0]
bb = [0]

for i in a:
    aa.append(aa[-1]+i)
for i in b:
    bb.append(bb[-1]+i)

import bisect
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    kk = k-aa[i]
    ans = max(ans, i+bisect.bisect_left(bb,kk))

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()))
c = a + b
c = sorted(c)
o = n + m

t = 0
for i in range(o):
    t += c[i]
    #print(t)
    if t == k:
        print(i+1)
        exit()
        break
    elif t > k:
        print(i)
        exit()
        break
print(m+n)

Submission status: Wrong Answer

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    Ap=0
    Bp=0
    n=0

    while True:
        if Ap+1>len(A) and Bp+1>len(B):
            break
        elif Ap+1>len(A):
            if K-B[Bp]>=0:
                n+=1
                K-=B[Bp]
                Bp+=1
            else:
                break
        elif Bp+1>len(B):
            if K-A[Ap]>=0:
                n+=1
                K-=A[Ap]
                Ap+=1
            else:
                break
        elif A[Ap]>B[Bp]:
            if K-B[Bp]>=0:
                n+=1
                K-=B[Bp]
                Bp+=1
            else:
                break
        else:
            if K-A[Ap]>=0:
                n+=1
                K-=A[Ap]
                Ap+=1
            else:
                break

    print(n)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n , m , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
su = 0
at = 0
bt = 0
ans=0
while su <= k:
    if at < n and bt < m:
        if a[at]<=b[bt]:
            su+=a[at]
            ans+=1
            at+=1
        else:
            su+=b[bt]
            ans+=1
            bt+=1
    elif bt<m:
        su+=b[bt]
        ans+=1
        bt+=1
    elif at<n:
        su+=a[at]
        ans+=1
        at+=1
    else:
        su=float('INF')
        ans=n+m+1
print(ans-1)

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

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

print(ans)