Imports System

Module Program
    Sub Main(args As String())

        Dim NMK() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()
        Dim A() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()
        Dim B() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()

        Dim ReadA(NMK(0)) As Long
        ReadA(0) = 0
        For i As Integer = 0 To NMK(0) - 1
            ReadA(i + 1) = ReadA(i) + A(i)
        Next
        Dim ReadB(NMK(1)) As Long
        ReadB(0) = 0
        For i As Integer = 0 To NMK(1) - 1
            ReadB(i + 1) = ReadB(i) + B(i)
        Next

        Dim ans As Integer = 0

        Dim iB As Integer = NMK(1)
        For i As Integer = 0 To NMK(0)      ' 0 - N books on desk A
            Dim NokoriJikan As Integer = NMK(2)
            If i <> 0 Then
                NokoriJikan -= ReadA(i)
            End If
            If NokoriJikan < 0 Then Exit For

            Dim ReadCount As Integer = i

            For j As Integer = iB To 0 Step -1      ' M - 0 books on desk B
                If ReadB(j) <= NokoriJikan Then
                    NokoriJikan -= ReadB(j)
                    iB = j
                    ReadCount += j
                    Exit For
                End If
            Next
            If ans < ReadCount Then
                ans = ReadCount
            End If
        Next

        Console.WriteLine(ans)

    End Sub

End Module
