Score : 500 points
问题陈述
给定 N 个线性函数 f1,f2,…,fN,其中 fi(x)=Aix+Bi。
对于一个由 K 个 不同 整数 1 到 N 组成的序列 p=(p1,p2,…,pK),找出 fp1(fp2(…fpK(1)…)) 的最大可能值。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given N linear functions f1,f2,…,fN, where fi(x)=Aix+Bi.
Find the maximum possible value of fp1(fp2(…fpK(1)…)) for a sequence p=(p1,p2,…,pK) of K distinct integers between 1 and N, inclusive.
Constraints
- 1≤N≤2×105
- 1≤K≤min(N,10)
- 1≤Ai,Bi≤50 (1≤i≤N)
- All input values are integers.
The input is given from Standard Input in the following format:
N K
A1 B1
A2 B2
⋮
AN BN
Output
Print the answer as an integer.
3 2
2 3
1 5
4 2
Sample Output 1
26
Here are all possible p and the corresponding values of fp1(fp2(1)):
- p=(1,2) : f1(f2(1))=15
- p=(1,3) : f1(f3(1))=15
- p=(2,1) : f2(f1(1))=10
- p=(2,3) : f2(f3(1))=11
- p=(3,1) : f3(f1(1))=22
- p=(3,2) : f3(f2(1))=26
Therefore, print 26.
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