Under construction

Still being built. Things may change

Artist

Interview

Time limit1sMemory limit512 MB

Summary
Choose exactly K blocks from N to minimize (sum of chosen widths) times (sum of chosen heights), where each block keeps its orientation.
Level

Medium7 of 10

Topics
Dynamic programming, Sorting, Greedy, Math
Solved
No attempts yet

Problem

Seungwon, better known by the pen name 'Nam Nam Seo', is an artist famous all over the world. Nobody else works the way he does, and every exhibition he opens fills up until there is no room left to stand.

Right now there are NN blocks in Seungwon's studio. He will pick exactly KK of them and build a new piece. He glues the chosen blocks from the lower left to the upper right so that they touch corner to corner, and he mounts the result on a canvas that fits it exactly.

A perfect piece matters a great deal to Seungwon, so he places every block parallel to the edges of the canvas, and he never swaps a block's width and height. That is, if the chosen blocks have widths and heights (w1w_1, h1h_1), (w2w_2, h2h_2), ⋯\cdots, (wKw_K, hKh_K), the canvas he needs has size (w1+w2+⋯+wKw_1 + w_2 + \cdots + w_K) ×\times (h1+h2+⋯+hKh_1 + h_2 + \cdots + h_K).

Seungwon wants the area of the canvas to be as small as possible. His art may be beyond us, but computing the minimum area of the canvas is not. Help him finish the piece.

Input

The first line contains the number of blocks Seungwon owns, NN (1≤N≤30001 \le N \le 3000), and the number of blocks he will use, KK (1≤K≤N1 \le K \le N), separated by a space.

Each of the next NN lines contains the width wiw_i and the height hih_i of one block, separated by a space. (1≤wi1 \le w_i, 1≤hi1 \le h_i, and the sum of all wiw_i and the sum of all hih_i are each at most 10910^9.)

Output

Print the minimum area of the canvas on the first line.

Examples2

  1. Example 1

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

    Input
    1 1
    1000000 1000
    
    Expected output
    1000000000