Under construction

Still being built. Things may change

Schools

Interview

Time limit2sMemory limit256 MB

Summary
Choose M cities for music schools and S other cities for sports schools to maximize the total number of attending students.
Level

Medium6 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

To support education, the administrator of a state decided to open exactly MM music schools and exactly SS sports schools. The state has NN different cities, and for every city you know how many students would attend a music school and how many would attend a sports school. The administrator never opens more than one school in a city, so each city gets one music school, one sports school, or no school at all.

If a music school opens in city ii, then AiA_i students attend it. If a sports school opens in city ii, then BiB_i students attend it.

Make the plan that maximizes the total number of students attending the new schools, and report that total.

Input

The first line contains the number of cities NN, the number of music schools to open MM, and the number of sports schools to open SS, separated by spaces (1≤N≤300 0001 \le N \le 300\,000, 0≤min⁡(M,S)0 \le \min(M, S), M+S≤NM + S \le N).

The ii-th of the next NN lines contains two integers AiA_i and BiB_i (1≤Ai≤100 0001 \le A_i \le 100\,000, 1≤Bi≤100 0001 \le B_i \le 100\,000). AiA_i is the number of students in city ii who want to study in a music school, and BiB_i is the number who want to study in a sports school.

Output

Print one integer, the total number of students attending the new schools in an optimal plan.

Examples2

  1. Example 1

    Input
    3 1 1
    5 2
    4 1
    6 4
    
    Expected output
    9
    
  2. Example 2

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