Express Train
InterviewTime limit1sMemory limit1024 MB
Pick exactly M stations for passing tracks to minimize the total running time of X regular trains and Y express trains.
Problem
The city plans to convert one subway line in Seoul into an express line. Unlike regular (local) trains, which stop at every station, express trains stop only at some stations. Passing tracks are built so that express trains can overtake regular trains.
The line will run two kinds of trains, regular and express. The line has stations, numbered 1 to , and both regular and express trains take minutes to run the whole line. If a passing track is built at station (), the running time of regular trains increases by minutes, and the running time of express trains decreases by minutes. Each station can have at most one passing track.
The line runs regular trains and express trains. The total running time of all trains is defined as (running time of a regular train) + (running time of an express train) . Choose exactly of the stations and build passing tracks there. Find the minimum possible total running time of all trains after the passing tracks are built.
Input
The first line contains , , , , and , separated by spaces.
The -th of the next lines contains and , separated by a space.
Output
On the first line, print the minimum possible total running time of all trains after the passing tracks are built.
Constraints
All input values are integers.
- . In other words, only inputs where the express running time stays positive after the passing tracks are built are given.