Bulb replacement
Time limit1sMemory limit256 MB
Byteasar assigns his bulbs to rooms and swaps at most k of them for store bulbs so every room meets its minimum and the total power is smallest.
Problem
Byteasar's new house needs only the finishing work. All that is left is to screw one bulb into each of the rooms. Every room has a minimum power that lights it well enough, so room needs a bulb of power at least .
Byteasar has already bought bulbs, and now he sees that they do not fit his plan. Some rooms may stay too dark, and some bulbs draw more power than the room needs. He decided to go to the store and swap a few bulbs, so that every room is lit well enough and the total power of the bulbs is as small as possible. The store has bulbs of every positive power. His backpack holds at most bulbs, so he can swap at most of them.
A bulb fits any room, so he places the bulbs into the rooms in any order he likes, one per room. Find the smallest possible total power of the bulbs in the house after swapping at most of them and lighting every room well enough.
Input
The first line has two integers and (), the number of rooms (which is also the number of bulbs) and the number of bulbs that fit in the backpack. Rooms are numbered from to .
The second line has integers (), the powers of the bulbs Byteasar owns.
The third line has integers (), the minimum power each room needs. Room needs a bulb of power at least .
Output
If swapping at most bulbs cannot light every room well enough, print NIE. Otherwise print one integer, the minimum total power of the bulbs in the house after swapping at most of them.
Hint
In the first example it is enough to swap the bulb of power for a bulb of power and the bulb of power for a bulb of power . Every room except the one that needs power then holds a bulb of exactly the power it needs, and that room holds a bulb of power .