8942: 涞坊路

内存限制:128 MB 时间限制:1.000 S 提交:3 解决:0
评测方式:文本比较 命题人:

题目描述

涞坊路是一条长 lns="http://www.w3.org/1998/Math/MathML"> 米的道路,道路上的坐标范围从 lns="http://www.w3.org/1998/Math/MathML">0 到 lns="http://www.w3.org/1998/Math/MathML">,路上有 lns="http://www.w3.org/1998/Math/MathML"> 座房子,第 lns="http://www.w3.org/1998/Math/MathML"> 座房子建在坐标为 lns="http://www.w3.org/1998/Math/MathML"> 的地方,其中住了 lns="http://www.w3.org/1998/Math/MathML"> 人。

松江 1843 路公交车要在这条路上建一个公交站,市政府希望让最多的人得到方便,因此希望所有的每一个的居民,从家到车站的距离的总和最短。

公交站应该建在哪里呢?

输入

第一行输入 lns="http://www.w3.org/1998/Math/MathML">lns="http://www.w3.org/1998/Math/MathML">

接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行两个整数 lns="http://www.w3.org/1998/Math/MathML"> 和 lns="http://www.w3.org/1998/Math/MathML">

输出

一个整数,最小的每个人从家到车站的距离的总和。

样例输入 复制

100 3
20 3
50 2
70 1

样例输出 复制

110

提示

样例解释 1

当建在坐标 lns="http://www.w3.org/1998/Math/MathML">40 的时候,所有人距离车站的距离总和为 lns="http://www.w3.org/1998/Math/MathML">2040×3+5040×2+7040×1=110