#B2048. Calculate Postage Based on Weight and Urgency
Calculate Postage Based on Weight and Urgency
Calculate Postage Based on Weight and Urgency
Given the weight of a mail item (in grams) and an urgency flag selected by the user, calculate the postage fee according to the following rules:
- If the weight is at most \(1000\) grams, the basic fee is \(8\) yuan.
- If the weight exceeds \(1000\) grams, for the excess part, every \(500\) grams (or part thereof) is charged an additional \(4\) yuan.
- If the user selects the urgent option, an extra \(5\) yuan is charged.
For example, if the weight is \(1700\) grams and the urgent service is selected, the extra weight is \(1700 - 1000 = 700\) grams which counts as 2 segments (since \(700/500 = 1.4\), rounded up to 2). The additional fee is \(2 \times 4 = 8\) yuan. Then, the total cost is \(8 + 8 + 5 = 21\) yuan.
inputFormat
The input consists of two integers separated by spaces:
- The first integer represents the weight of the mail item (in grams).
- The second integer is a flag:
1
if the user chooses the urgent option, and0
otherwise.
outputFormat
Output a single integer representing the total postage fee.
sample
1000 0
8