아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

(N+1)-legged race

시간 제한2초메모리 제한1024 MB

요약
N명의 학생을 골라 순서를 정할 때, 능력치 합에서 이웃한 학생 사이 키 차이의 합을 뺀 값이 최대가 되도록 한다.
난이도

보통10점 중 7점

유형
동적 계획법, 정렬
정답자
아직 제출이 없습니다

문제

You are a teacher of a class of SS students. The students are numbered from 11 to SS, and the ii-th student has athletic ability A_iA\_i and height H_iH\_i.

In an upcoming sports day your class is going to compete in a game called (N+1N+1)-legged race. In this race NN runners of a team line up in a row, connect their legs using ankle straps (more precisely, connect the first runner's right leg and the second runner's left leg, the second runner's right leg and the third runner's left leg, and so on), and run together toward a goal.

As the teacher of the class you have to choose NN students from your class as runners of the race and decide the order of these NN runners. Of course, each runner's athletic ability is one of the key factors of the strength of the team. However, you have noticed that if two adjacent runners have very different heights, it ends up losing the strength of the team. After all, if students of numbers r_1,…,r_Nr\_1, \dots , r\_N line up in this order, the strength of this team is defined as follows.

  • ∑_i=1NA_r_i−∑_i=1N−1∣H_r_i−H_r_i+1∣\sum\_{i=1}^{N}{A\_{r\_i}} - \sum\_{i=1}^{N-1}{\left| H\_{r\_i} - H\_{r\_{i+1}}\right|}

Your task is to maximize the strength of the team.

입력

The input consists of a single test case of the following format.

SS NN

A_1A\_1 H_1H\_1

⋮\vdots

A_SvA\_Sv H_S$

The first line contains two integers SS and NN (2≤S≤1052 ≤ S ≤ 10^5, 2≤N≤min⁡(S,200)2 ≤ N ≤ \min{(S, 200)}), which represent the number of students in your class and the number of students that you have to choose from your class as runners. Each of the next SS lines contains two integers A_iA\_i and H_iH\_i (1≤A_i,H_i≤1091 ≤ A\_i, H\_i ≤ 10^9), which represent the athletic ability and height of the ii-th student in your class.

출력

Print the maximum strength of the team that you can accomplish.

예제4

  1. 예제 1

    입력
    4 2
    40 150
    100 185
    60 160
    80 170
    
    예상 출력
    165
    
  2. 예제 2

    입력
    4 3
    40 150
    100 185
    60 160
    80 170
    
    예상 출력
    215
    
  3. 예제 3

    입력
    4 3
    40 150
    100 300
    60 160
    80 140
    
    예상 출력
    160
    
  4. 예제 4

    입력
    10 5
    31 41
    59 26
    53 58
    97 93
    23 84
    62 64
    33 83
    27 95
    2 84
    19 71
    
    예상 출력
    237