We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Fair Cut

Fair Cut

Problem
Submissions
Leaderboard
Discussions
Editorial

Li and Lu have integers, , that they want to divide fairly between the two of them. They decide that if Li gets integers with indices (which implies that Lu gets integers with indices ), then the measure of unfairness of this division is:

Find the minimum measure of unfairness that can be obtained with some division of the set of integers where Li gets exactly integers.

Note means Set complement

Input Format

The first line contains two space-separated integers denoting the respective values of (the number of integers Li and Lu have) and (the number of integers Li wants).
The second line contains space-separated integers describing the respective values of .

Constraints

  • For of the test cases, .
  • For of the test cases, .

Output Format

Print a single integer denoting the minimum measure of unfairness of some division where Li gets integers.

Sample Input 0

4 2
4 3 1 2

Sample Output 0

 6

Explanation 0
One possible solution for this input is .

Sample Input 1

4 1
3 3 3 1

Sample Output 1

2

Explanation 1
The following division of numbers is optimal for this input: .

Author

tunyash

Difficulty

Medium

Max Score

40

Submitted By

4973

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website