K Best

Time limit2sMemory limit64 MB

Summary
Choose exactly k jewels out of n to maximize the ratio of total value to total weight, using binary search on the answer with a fractional feasibility check, then output the exact reduced fraction.
Level

Medium7 of 10

Topics
Binary search, Greedy, Math
Solved
No attempts yet

Problem

Demy has nn jewels. The ii-th jewel has value viv_i and weight wiw_i.

She wants to keep exactly kk of them so that their specific value is as large as possible. For a chosen set S={i1,i2,…,ik}S = \{i_1, i_2, \ldots, i_k\} the specific value is defined as

s(S)=∑j=1kvij∑j=1kwij.s(S) = \frac{\sum_{j=1}^{k} v_{i_j}}{\sum_{j=1}^{k} w_{i_j}}.

Determine the maximum possible specific value over all subsets of size kk.

Input

The first line contains two integers nn and kk — the number of jewels and the number to keep (1≤k≤n≤100 0001 \le k \le n \le 100\,000).

Each of the next nn lines contains two integers viv_i and wiw_i (0≤vi≤1060 \le v_i \le 10^6, 1≤wi≤1061 \le w_i \le 10^6). Both ∑vi\sum v_i and ∑wi\sum w_i are at most 10710^7.

Output

The maximum specific value is a rational number. Output it as an irreducible fraction p/q, where p≥0p \ge 0 and q≥1q \ge 1 are integers with gcd⁡(p,q)=1\gcd(p, q) = 1. Always print the denominator (for example 3/1). If the value is 00, print 0/1.

Examples4

  1. Example 1

    Input
    3 2
    1 1
    1 2
    1 3
    
    Expected output
    2/3
    
  2. Example 2

    Input
    1 1
    5 2
    
    Expected output
    5/2
    
  3. Example 3

    Input
    3 1
    1 2
    3 1
    2 5
    
    Expected output
    3/1
    
  4. Example 4

    Input
    4 4
    1 1
    2 2
    3 3
    4 4
    
    Expected output
    1/1