QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#2103. Equipment Upgrade

Statistics

Yi Ai currently has $n$ pieces of equipment, all of which are in their initial state, which we call level $0$. Each piece of equipment can be upgraded exactly twice. For the $i$-th piece of equipment, upgrading from level $0$ to level $1$ costs $w_{i,1}$ gold coins, and upgrading from level $1$ to level $2$ costs $w_{i,2}$ gold coins.

Yi Ai wants to know the minimum number of gold coins required to perform a total of $m$ upgrades across her equipment.

Input

The input is read from standard input.

The first line contains two positive integers $n$ and $m$, representing the total number of equipment pieces and the total number of upgrades required.

The next $n$ lines each contain two positive integers $w_{i, 1}$ and $w_{i, 2}$, representing the costs of the two upgrades for the $i$-th piece of equipment.

Output

The output is written to standard output.

Output a single positive integer representing the minimum number of gold coins required.

Examples

Input 1

5 7
1 3
2 1
2 5
4 2
1 1

Output 1

11

Note 1

The chosen upgrades are:

  • Upgrade the first piece of equipment to level 2.
  • Upgrade the second piece of equipment to level 2.
  • Upgrade the third piece of equipment to level 1.
  • Upgrade the fifth piece of equipment to level 2.

The total cost is $(1+3)+(2+1)+2+(1+1)=11$ gold coins.

Input 2

See ex_2.in and ex_2.ans in the download directory.

Subtasks

For $100\%$ of the data, it is guaranteed that $1\le n \le 5 \times 10^{5}, 1\le m\le 2n, w_{i,j} \le 10^{9}$.

Test Case$n$Special Property
1,2,3$\le 3,000$None
4,5,6$\le 10^{5}$A
7,8B
9None
10$\le 5 \times 10^{5}$

Special Property A: For all $i$, $w_{i,1} \ge w_{i,2}$ holds.

Special Property B: For all $i$, $w_{i,1} \le w_{i,2}$ holds.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.