#C2818. Minimum Total Delivery Distance

    ID: 46176 Type: Default 1000ms 256MiB

Minimum Total Delivery Distance

Minimum Total Delivery Distance

You are given a conveyor belt with n delivery points indexed from 0 to n-1, and a list of m packages. Each package is represented by two integers: its weight and the index of its delivery destination.

Your task is to determine the minimum total distance traveled by all packages. The distance traveled by a single package is calculated as the product of its weight and the index of its delivery point. Mathematically, the total distance is given by:

\(\text{Total Distance} = \sum_{i=1}^{m} (\text{weight}_i \times \text{delivery\_point}_i)\)

Note: Although the number of delivery points n is provided, it is not used in the calculation.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains two integers n and m, where n is the number of delivery points and m is the number of packages.
  2. The next m lines each contain two integers: the weight of a package and the delivery point's index.

Each value is separated by whitespace.

outputFormat

Output a single integer to standard output (stdout): the minimum total distance traveled by all packages, computed as:

\(\sum_{i=1}^{m} (\text{weight}_i \times \text{delivery\_point}_i)\)

## sample
3 1
5 2
10

</p>