#B4073. Express Delivery Fee Calculation

    ID: 11730 Type: Default 1000ms 256MiB

Express Delivery Fee Calculation

Express Delivery Fee Calculation

A courier company charges delivery fees based on the weight of the item and the destination region. The fee structure is as follows:

  • If the weight \(w\) (in grams) is within \(500\) grams, the fee is \(20\) Yuan.
  • If \(w > 500\), the base fee is \(20\) Yuan, and the excess weight is charged additionally. The excess weight is defined as \(w - 500\). For every additional \(500\) grams (or any part thereof), an extra fee is charged.

In mathematical terms, if we define \(k\) as the number of extra \(500\)-gram units needed (i.e. \( k = \lceil (w - 500)/500 \rceil \)), then the total fee is given by:

\[ \text{Total Fee} = 20 + k \times A \]

where \(A\) is the additional fee per unit weight depending on the destination region. The regions and their corresponding additional fees are as follows:

  1. Region 1: \(A = 4\) Yuan
  2. Region 2: \(A = 6\) Yuan
  3. Region 3: \(A = 9\) Yuan
  4. Region 4: \(A = 10\) Yuan
  5. Region 5: \(A = 17\) Yuan

For example, if \(w = 1020\) grams and the destination is region 1, the extra weight is \(1020 - 500 = 520\) grams, which constitutes \(\lceil 520/500 \rceil = 2\) units. The extra charge is \(2 \times 4 = 8\) Yuan, resulting in a total fee of \(20 + 8 = 28\) Yuan.

inputFormat

The input consists of two integers separated by a space. The first integer (w) (in grams) represents the weight of the item, and the second integer (n) (from 1 to 5) represents the destination region.

outputFormat

Output a single integer representing the total delivery fee in Yuan.

sample

500 1
20