Under construction

Still being built. Things may change

Seats

Time limit2sMemory limit512 MB

Summary
Choose K of N passengers to sit in a row of L seats, maximizing the sum of A_i plus B_i per adjacent empty seat, for every K from 1 to N.
Level

Hard9 of 10

Topics
Dynamic programming, Divide and conquer, Sorting
Solved
No attempts yet

Problem

The subway in town X is a bit unusual. A train has a single wagon with one row of LL seats. The wagon holds NN passengers, numbered from 00 to N−1N-1. Each passenger gets pleasure as follows:

  • If a passenger is standing, the pleasure is 00.
  • If a passenger is sitting, the passenger gets AiA_i pleasure from sitting, plus BiB_i pleasure for each empty seat between the passenger and a neighboring passenger or the end of the row.

For example, let there be 3 passengers with A0=5A_0=5, B0=2B_0=2, A1=10A_1=10, B1=1B_1=1, A2=1A_2=1, B2=1B_2=1, and let L=6L=6. Consider this seating, where _ is an empty seat:

_ 0 _ _ 1 _

Passenger 2 is standing.

  • Passenger 0 gets 55 for sitting and 66 for the empty seats (1 on the left and 2 on the right), for a total of 1111.
  • Passenger 1 gets 1010 for sitting and 33 for the empty seats (2 on the left and 1 on the right), for a total of 1313.
  • Passenger 2 gets 00 because the passenger is standing.

The total pleasure of all passengers is 2424.

Write a program that, given NN, LL, and the characteristics of each passenger, finds the maximum possible total pleasure for every number of seated passengers from 11 to NN.

Input

The first line contains two integers NN and LL, the number of passengers and the number of seats. Each of the next NN lines contains two non-negative integers AiA_i and BiB_i for passenger ii.

Output

Print NN lines. The KK-th line contains the maximum total pleasure the passengers can get when exactly KK of them are sitting. For K>LK > L, print 00, because no valid configuration of KK passengers fits in LL seats.

Constraints

  • 1≤N≤100 0001 \le N \le 100\,000
  • 1≤L≤200 0001 \le L \le 200\,000
  • 0<Ai,Bi<1090 < A_i, B_i < 10^9

Examples2

  1. Example 1

    Input
    3 2
    1 2
    3 4
    5 6
    
    Expected output
    11
    8
    0
    
  2. Example 2

    Input
    3 3
    1 2
    3 4
    5 100
    
    Expected output
    205
    112
    9