#P4293. Maximizing Particle Connection Energy
Maximizing Particle Connection Energy
Maximizing Particle Connection Energy
In a mysterious energy field, there are n particles. Each particle has two properties: mass m and coupling coefficient c. Every particle has two poles, N and S. When two particles meet, only connections between one particle's N pole and the other's S pole are allowed. When particle a with mass \(m_a\) and coefficient \(c_a\) connects its N pole to particle b with mass \(m_b\) and coefficient \(c_b\)'s S pole, the binding energy produced is given by:
[ E = m_a m_b (c_a - c_b) ]
Your task is to solve two problems:
- Direct Pair Connection: Among the n particles, choose two distinct particles such that when particle a uses its N pole and particle b uses its S pole to connect, the energy \(E = m_a m_b (c_a - c_b)\) is maximized. Note that the order matters.
- Circular Connection: Dongdong invented a method where you can select any k particles \(p_1, p_2, \dots, p_k\) (all distinct, with \(1 \le k \le n\)) and then connect them in a cycle as follows: connect \(p_i\)'s N pole to \(p_{i+1}\)'s S pole for \(1 \le i
[ E_{cycle} = \sum_{i=1}^{k} m_{p_i} m_{p_{i+1}} (c_{p_i} - c_{p_{i+1}})]
where indices are taken modulo (k) (so that (p_{k+1}) is (p_1)). Determine the maximum cycle energy that can be obtained. (Note that if you choose only one particle, the energy is defined as 0.)
</p>
Input format: The first line contains an integer n. Each of the following n lines contains two integers representing the mass m and the coupling coefficient c of a particle.
Output format: Output two space‐separated integers: the first is the maximum energy produced by a direct pair connection, and the second is the maximum cycle energy using Dongdong's method.
inputFormat
The input begins with an integer n (n ≥ 1). Following this are n lines, each containing two integers: m and c (the mass and coupling coefficient of a particle). It is guaranteed that if n is 1 then the answer for the first part is defined as 0.
outputFormat
Output two space‐separated integers: the maximum energy from a direct pair connection and the maximum cycle energy from Dongdong's method.
sample
2
2 3
4 1
16 0