#P4131. [WC2005] 友好的生物

    ID: 3064 远端评测题 500ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2005WC/CTSC/集训队Special Judge枚举,暴力状态压缩,状压

[WC2005] 友好的生物

Description

Planet WW is a world with an Earth-like climate and a diverse collection of species. After years of research, xenobiologists have discovered tens of thousands of species, and the number keeps growing.

Species on planet WW are interesting: some pairs are very friendly, always together and inseparable; others are hostile and fight upon meeting. To better understand their degrees of friendliness, the xenobiologists want to run some quantitative calculations. They have found that the friendliness between two species depends on their KK attributes, temporarily numbered as attribute 11, attribute 22, …, attribute KK, all of which are quantifiable. Their research suggests that the larger the differences in the first K1K-1 attributes, the friendlier the pair; but attribute KK is special: the smaller the difference in this attribute, the friendlier the pair.

Therefore, they conjecture that the following formula can quantify the friendliness between two species: Friendliness=(i=1k1Cidi)CKdKFriendliness=(\sum_{i=1}^{k-1} C_id_i)-C_Kd_K,

where CiC_i are non-negative constants and did_i is the difference in attribute ii (i.e., the absolute difference). If the attributes of each species are known, the above formula makes it easy to compute the friendliness between any pair. Now the xenobiologists ask: among the species discovered so far, which pair is the friendliest, and what is their friendliness?

Input Format

The first line contains two integers NN and KK, the number of discovered species and the number of attributes, respectively.

The second line contains KK non-negative integers CiC_i, the constants used to compute the friendliness.

The next NN lines describe each species, numbered in order as species 11, species 22, …, species NN. Each line contains KK integers, giving the values of attributes 11, 22, …, KK for that species.

Output Format

Output two lines. The first line contains two integers ii and jj (iji \neq j), indicating that the friendliest pair you found is species ii and species jj. If there is more than one friendliest pair, output any one of them.

The second line contains an integer, the friendliness between species ii and species jj.

5 3
1 2 3
-5 3 2
-2 3 0
0 5 9
3 4 -1
-10 -11 7
3 5
36

Hint

[Sample Explanation]

The friendliness between species 33 and 55 is $1\times |0-(-10)|+2\times |5-(-11)|-3\times |9-7|=36$.

[Constraints]

  • 2N100,0002 \leq N \leq 100{,}000.
  • 2K52 \leq K \leq 5.
  • 0Ci1000 \leq C_i \leq 100.
  • Each attribute value is at least 10000-10000 and at most 1000010000.
  • The maximum friendliness is guaranteed to be greater than 00.

Translated by ChatGPT 5