oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

collectmushrooms5 Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

collectmushrooms.html

Problem Description

Gug is collecting mushrooms again. There are N farms from which Gug can collect mushrooms. Each farm only has two mushrooms for Gug to collect. To collect the first mushroom from farm i costs Ai dollars, and collecting the second mushroom from farm i costs Bi dollars. The first mushroom must be collected before the second mushroom. Gug needs M mushrooms in total. Find out the minimum amount of money, in dollars, he must pay.

Input

The first line of input will consist of two integers, N and M.

The next N lines of input will contain two integers each, Ai and Bi.

Output

The output should contain one integer, the minimum amount of money Gug needs to pay.

Limits

For all subtasks: 1 ≤ M ≤ 2N, 1 ≤ Ai, Bi ≤ 109.

Subtask 1 (25%): 1 ≤ N ≤ 1000.

Subtask 2 (10%): 1 ≤ N ≤ 200000, Ai = 1.

Subtask 3 (11%): 1 ≤ N ≤ 200000, Ai = Bi.

Subtask 4 (22%): 1 ≤ N ≤ 200000, Ai ≤ Bi.

Subtask 5 (32%): 1 ≤ N ≤ 200000.

Subtask 6 (0%): Sample Testcases.

Sample Input 1

2 3
1 1
1 1

Sample Output 1

3

Sample Input 2

5 3
10 10
5 5
10 10
6 3
25 5

Sample Output 2

14

Tags

Greedy, Data Structure

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
125221s256MBMinimum
210211s256MBMinimum
311211s256MBMinimum
422611s256MBMinimum
5321021s256MBMinimum
6021s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o collectmushrooms5 -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.