
Imports System.Console
Module Module1
    Dim n, m, k As Integer
    Dim dp() As Int64
    Dim a() As Int64
    Dim b() As Int64
    Sub Main()
        Dim s1() As String = ReadLine().Split
        n = s1(0)
        m = s1(1)
        k = s1(2)
        Dim da() As String = ReadLine.Split
        Dim db() As String = ReadLine.Split
        ReDim a(n)
        ReDim b(m)
        Dim w1, w2 As Int64
        For i = 1 To n
            w1 += da(i - 1)
            a(i) = w1
        Next
        For i = 1 To m
            w2 += db(i - 1)
            b(i) = w2
        Next
        Dim max As Int64
        ReDim dp(n)
        For i = 0 To n
            If k >= a(i) Then
                dp(i) = B_read(i)
                If dp(i) + i > max Then
                    max = dp(i) + i
                End If
            End If
        Next
        WriteLine(max)
    End Sub
    Private Function B_read(ByVal n As Integer)
        Dim nokori As Int64 = k - a(n)
        Dim w As Integer = dp(n - 1)
        Do Until w > m OrElse b(w) > nokori
            w += 1
        Loop
        w -= 1
        Return w
    End Function
End Module
