CF1151D.Stas and the Queue at the Buffet
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
During a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of n high school students numbered from 1 to n. Initially, each student i is on position i. Each student i is characterized by two numbers — ai and bi. Dissatisfaction of the person i equals the product of ai by the number of people standing to the left of his position, add the product bi by the number of people standing to the right of his position. Formally, the dissatisfaction of the student i, which is on the position j, equals ai⋅(j−1)+bi⋅(n−j).
The director entrusted Stas with the task: rearrange the people in the queue so that minimize the total dissatisfaction.
Although Stas is able to solve such problems, this was not given to him. He turned for help to you.
在克雷姆兰王国科学中学的自助餐厅休息期间,排起了由 n 名中学生组成的队伍,学生编号从 1 到 n。初始时,每名学生 i 位于位置 i。每名学生 i 由两个数 ai 和 bi 表征。学生 i 的不满值等于 ai 乘以其左侧人数,加上 bi 乘以其右侧人数。形式化地,若学生 i 位于位置 j,则其不满值为 ai⋅(j−1)+bi⋅(n−j)。
校长委派斯塔斯完成一项任务:重新安排队列中人员的顺序,使得总不满值最小。
尽管斯塔斯有能力解决此类问题,但这次他并未被指派完成该任务。他向你求助。
输入格式
The first line contains a single integer n (1≤n≤105) — the number of people in the queue.
Each of the following n lines contains two integers ai and bi (1≤ai,bi≤108) — the characteristic of the student i, initially on the position i.
第一行包含一个整数 n(1≤n≤105)—— 队列中的人数。
接下来的 n 行,每行包含两个整数 ai 和 bi(1≤ai,bi≤108)—— 表示初始位于位置 i 的学生 i 的特征值。
输出格式
Output one integer — minimum total dissatisfaction which can be achieved by rearranging people in the queue.
输出一个整数——通过重新排列队列中的人所能达到的最小总不满值。
输入输出样例
输入#1
3 4 2 2 3 6 1
输出#1
12
输入#2
4 2 4 3 3 7 1 2 3
输出#2
25
输入#3
10 5 10 12 4 31 45 20 55 30 17 29 30 41 32 7 1 5 5 3 15
输出#3
1423
说明/提示
In the first example it is optimal to put people in this order: (3,1,2). The first person is in the position of 2, then his dissatisfaction will be equal to 4⋅1+2⋅1=6. The second person is in the position of 3, his dissatisfaction will be equal to 2⋅2+3⋅0=4. The third person is in the position of 1, his dissatisfaction will be equal to 6⋅0+1⋅2=2. The total dissatisfaction will be 12.
In the second example, you need to put people in this order: (3,2,4,1). The total dissatisfaction will be 25.
在第一个例子中,将人员按顺序 (3,1,2) 安排是最优的。第一个人位于位置 2,其不满值为 4⋅1+2⋅1=6;第二个人位于位置 3,其不满值为 2⋅2+3⋅0=4;第三个人位于位置 1,其不满值为 6⋅0+1⋅2=2。总不满值为 12。
在第二个例子中,需将人员按顺序 (3,2,4,1) 安排。总不满值为 25。
输入解题思路,AI测评打分。不知道怎么写?