Merge Fruits
题号:NC273396
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Dodo, who reincarnated into the magical world, is managing a superpower orchard. The energy of this superpower orchard is generated by the process of merging fruits. Now, all the fruits have been picked by and arranged in a row.

Specifically, each fruit has two energy attributes, a and b. Considering two adjacent fruits with the left one denoted as (a_1, b_1) and the right one as (a_2, b_2), merging them can release energy a_1 * b_2 and produce a new fruit (a_2, b_1).

Dodo hired a magician to multiply the initial energy attributes a and b of a contiguous interval (at least one) of fruits by k. Then, pairs of adjacent fruits are chosen for merging until only one fruit remains.

Dodo wants to maximize the energy released by merging all the fruits. Please help Dodo calculate the maximum amount of energy that can be released.

输入描述:

The first line consists of two integers n, k, indicating the total number of fruits and the integer k by which the magician can multiply a contiguous interval of fruits. Please note that k may be negative.

The following n lines each contain two integers a_i, b_i, representing the two attributes of the i-th fruit from left to right. Please note that attributes may be negative.

输出描述:

One line with a single integer representing the answer.
示例1

输入

复制
2 2
1 2
3 4

输出

复制
16
示例2

输入

复制
3 2
1 2
-3 -4
5 6

输出

复制
-26

说明

Due to negative numbers, changing the first one to (2,4) is the best solution.

备注:

2 \le n \le 10^5-1000 \le k, a_i, b_i \le 1000