Club Room Repairs
InterviewTime limit2sMemory limit512 MB
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 club rooms. One day a villain wrecked every one of them and drove the clubs out, leaving nothing but rubble.
clubs are now without a room, and club holds a budget of won. Each club wants to repair one room out of that budget and use it. Making room usable again costs 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 is assigned room , the club pays up to won from its own budget and Jongbin covers the shortfall of won. The total amount Jongbin pays out cannot exceed won.
Find the largest number of clubs that can end up with a room.
Input
The first line contains , , and . (, , )
The second line contains the repair costs of the rooms in order. ()
The third line contains the budgets of the clubs in order. ()
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 , the club budgets are , and .
Give the room costing to the club with budget , the room costing to the club with budget , and the room costing to the club with budget . All three clubs cover their own repair, so Jongbin spends nothing and clubs get a room.
Seating all clubs would force Jongbin to pay at least won, which is over the limit of , so four is impossible.