luogu#P5094. [USACO04OPEN] MooFest G 加强版

[USACO04OPEN] MooFest G 加强版

Problem Description

Every year, John’s NN cows take part in the MooFest, a big festival for cows all over the world. The festival has many fun activities, such as haystack piling contests and cow-pen jumping contests. Sometimes the cows also poke each other for fun. Of course, they will line up and moo loudly to celebrate their holiday.

The cows’ moos are so noisy that each cow’s hearing is damaged to a different degree. Now you are given cow ii’s hearing level viv_i. This means that if cow jj wants to say something that cow ii can hear, cow jj must use a volume greater than vi×dis(i,j)v_i \times dis(i,j). Therefore, if cows ii and jj want to talk to each other, their volume must be at least max(vi,vj)×dis(i,j)\max(v_i, v_j) \times dis(i,j), where dis(i,j)dis(i,j) is the distance between them.

Now the NN cows are standing on a straight line, and each cow has a coordinate xix_i. If every pair of cows is talking, and each pair uses the minimum required volume, what is the sum of the volumes over all N(N1)/2N(N-1)/2 pairs?

Input Format

The first line contains an integer NN.

The next NN lines each contain two numbers viv_i and xix_i, representing the ii-th cow’s hearing level and coordinate, respectively.

Output Format

Output one number, which is the sum of the volumes when these N(N1)/2N(N-1)/2 pairs of cows talk.

4
3 1
2 5
2 6
4 3
57

Hint

Constraints

Since an O(N2)O(N^2) algorithm can pass under the original data, some additional enhanced testdata has been added.

The original data is Subtask 11, and the newly added data is Subtask 22.

  • Subtask 11 (11 point): 1N,Vi,xi2×1041 \leq N, V_i, x_i \leq 2 \times 10^4.
  • Subtask 22 (9999 points): 1N,Vi,xi5×1041 \leq N, V_i, x_i \leq 5 \times 10^4.

Translated by ChatGPT 5