#abc366f. F - Maximum Composition

F - Maximum Composition

Score : 500500 points

问题陈述

给定 NN 个线性函数 f1,f2,,fNf_1, f_2, \ldots, f_N,其中 fi(x)=Aix+Bif_i(x) = A_i x + B_i

对于一个由 KK不同 整数 11NN 组成的序列 p=(p1,p2,,pK)p = (p_1, p_2, \ldots, p_K),找出 fp1(fp2(fpK(1)))f_{p_1}(f_{p_2}(\ldots f_{p_K}(1) \ldots )) 的最大可能值。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given NN linear functions f1,f2,,fNf_1, f_2, \ldots, f_N, where fi(x)=Aix+Bif_i(x) = A_i x + B_i.

Find the maximum possible value of fp1(fp2(fpK(1)))f_{p_1}(f_{p_2}(\ldots f_{p_K}(1) \ldots )) for a sequence p=(p1,p2,,pK)p = (p_1, p_2, \ldots, p_K) of KK distinct integers between 11 and NN, inclusive.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^{5}
  • 1Kmin(N,10)1 \leq K \leq \text{min}(N,10)
  • 1Ai,Bi501 \leq A_i, B_i \leq 50 (1iN)(1 \leq i \leq N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN KK

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

Output

Print the answer as an integer.

Sample Input 1

3 2
2 3
1 5
4 2

Sample Output 1

26

Here are all possible pp and the corresponding values of fp1(fp2(1))f_{p_1}(f_{p_2}(1)):

  • p=(1,2)p= ( 1,2 ) : f1(f2(1))=15f_1(f_2(1))=15
  • p=(1,3)p= ( 1,3 ) : f1(f3(1))=15f_1(f_3(1))=15
  • p=(2,1)p= ( 2,1 ) : f2(f1(1))=10f_2(f_1(1))=10
  • p=(2,3)p= ( 2,3 ) : f2(f3(1))=11f_2(f_3(1))=11
  • p=(3,1)p= ( 3,1 ) : f3(f1(1))=22f_3(f_1(1))=22
  • p=(3,2)p= ( 3,2 ) : f3(f2(1))=26f_3(f_2(1))=26

Therefore, print 2626.

Sample Input 2

10 3
48 40
34 22
24 37
45 40
48 31
49 44
45 40
44 6
35 22
39 28

Sample Output 2

216223
}