Under construction

Still being built. Things may change

Club Room Repairs

Interview

Time limit2sMemory limit512 MB

Summary
Assign each club at most one room and each room at most one club, where Jongbin covers max(0, cost - budget) up to X total; maximize clubs housed.
Level

Medium6 of 10

Topics
Greedy, Sorting, Two pointers, Binary search
Solved
No attempts yet

Problem

A university had NN club rooms. One day a villain wrecked every one of them and drove the clubs out, leaving nothing but rubble.

MM clubs are now without a room, and club ii holds a budget of SiS_i won. Each club wants to repair one room out of that budget and use it. Making room jj usable again costs CjC_j won. A room takes at most one club, and a club takes at most one room. A club with money left over after a repair does not hand it to another club.

Jongbin knows how it feels to have no club room, so he helps the clubs that cannot cover a room on their own. When club ii is assigned room jj, the club pays up to SiS_i won from its own budget and Jongbin covers the shortfall of max⁡(0,Cj−Si)\max(0, C_j - S_i) won. The total amount Jongbin pays out cannot exceed XX won.

Find the largest number of clubs that can end up with a room.

Input

The first line contains NN, MM, and XX. (1≤N≤1000001 \le N \le 100000, 1≤M≤1000001 \le M \le 100000, 0≤X≤10000000000 \le X \le 1000000000)

The second line contains the repair costs C1,C2,…,CNC_1, C_2, \dots, C_N of the NN rooms in order. (0≤Cj≤10000000000 \le C_j \le 1000000000)

The third line contains the budgets S1,S2,…,SMS_1, S_2, \dots, S_M of the MM clubs in order. (0≤Si≤10000000000 \le S_i \le 1000000000)

Output

Print on one line the largest number of clubs that can end up with a room.

Explanation

Take the case where the repair costs are 5,8,9,1,75, 8, 9, 1, 7, the club budgets are 2,10,5,32, 10, 5, 3, and X=3X = 3.

Give the room costing 99 to the club with budget 1010, the room costing 55 to the club with budget 55, and the room costing 11 to the club with budget 33. All three clubs cover their own repair, so Jongbin spends nothing and 33 clubs get a room.

Seating all 44 clubs would force Jongbin to pay at least 44 won, which is over the limit of 33, so four is impossible.

Examples2

  1. Example 1

    Input
    3 4 0
    1 2 3
    3 3 3 3
    
    Expected output
    3
    
  2. Example 2

    Input
    5 4 3
    5 8 9 1 7
    2 10 5 3
    
    Expected output
    3