App
Time limit1sMemory limit128 MB
Choose a subset of active apps to deactivate whose freed memory is at least M while minimizing the total deactivation cost.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
While using a smartphone we run many apps. Usually only one app is visibly "running" on the screen, but many more are "active" without being shown. An app being active means that, even if it is not visible, its most recent state is kept in main memory. The reason for keeping it there even when it is not currently running is so that, when the user reopens a previously used app, its last state can be read back from main memory to finish preparing to run quickly.
However, a smartphone's memory is limited, so if every app that was ever launched is kept active in main memory, memory shortages arise easily. When there is not enough memory to launch a new app, the operating system has no choice but to select some active apps and remove them from memory. This process is called "deactivating" an app.
When memory runs low, deactivating active apps at random until enough memory is freed is not a good approach, because relaunching a deactivated app takes extra time. Write a program that solves this deactivation problem smartly.
Suppose apps are currently active. Each app is using bytes of memory. Let be a numeric value (time, etc.) for the extra cost of relaunching app after it has been deactivated. The user wants to launch a new app and needs additional bytes of memory. That is, you must deactivate some of the active apps to free at least additional bytes. Among all such ways, find the one that minimizes the sum of the costs of the deactivated apps, and output that minimum cost.
Input
The input consists of three lines. The first line contains two integers and separated by a space. The second line contains integers separated by spaces, the number of bytes of memory used by the active apps. The third line contains integers separated by spaces, the cost of deactivating each app.
Constraints: , , , , and .
Output
Print, on a single line, the minimum cost of deactivating apps to free bytes.