You are given a circular knapsack and
The overall beauty value of the knapsack is defined as:
where the overall beauty value of the knapsack is the sum of the item's value minus the absolute difference of the beauty score between the current item with the next adjacent item.
Your task is to help Bob maximize the overall beauty value of the knapsack.
Input Specification
The first line of input contains two integers,
Each of the following
Output Specification
Output one integer, the max overall beauty value of the knapsack.
Constraints
Subtask | Points | Additional constraints |
---|---|---|
No additional constraints. |
Sample Input
5 3
2 1
4 2
6 4
8 8
10 16
Sample Output
6
Explanation
Bob can put items
Comments