【Codefroces 717 C. Potions Homework】
来源:互联网 发布:mac 桌面菜单栏不见了 编辑:程序博客网 时间:2024/05/13 06:48
C. Potions Homework
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class.
Each of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student’s laziness level is equal to their task’s difficulty level. Both sets of values are given by the sequence a, where ai represents both the laziness level of the i-th student and the difficulty of his task.
The time a student needs to finish a task is equal to the product of their laziness level and the task’s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007.
Input
The first line of input contains integer n (1 ≤ n ≤ 100 000) — the number of tasks. The next n lines contain exactly one integer number ai (1 ≤ ai ≤ 100 000) — both the difficulty of the initial task and the laziness of the i-th students.
Output
Print the minimum total time to finish all tasks modulo 10 007.
Example
input
2
1
3
output
6
Note
In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.
时间 = 懒惰程度 × 难度系数
最少时间 = sort?
AC代码:
#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;const int mod = 10007;const int K = 1e5 + 10;LL a[K];int main(){ int N; scanf("%d",&N); for(int i = 1 ; i <= N; i++) scanf("%lld",&a[i]); sort(a + 1, a + 1 + N); LL ans = 0; for(int i = 1 ; i <= N; i++) ans = (ans + a[i] * a[N - i + 1]) % mod; printf("%lld\n",ans); return 0;}
- 【Codefroces 717 C. Potions Homework】
- Codeforces Problem 717C Potions Homework(排序)
- [排序不等式] Codeforces 717C Bubble Cup 9 - Finals C. Potions Homework
- Bubble Cup 9 - Finals [Online Mirror] C. Potions Homework (水题)
- C homework
- codeforces 734C Anton and Making Potions
- Codeforces 734C. Anton and Making Potions
- CodeForces 734C - Anton and Making Potions
- CodeForce-734C Anton and Making Potions
- 734C Anton and Making Potions
- CodeFroces 412.C Success Rate
- CodeFroces 412.C Success Rate
- codefroces 33C Wonderful Randomized Sum DP
- Codefroces 279 div2 C. Hacking Cypher
- CodeFroces # 285 DIV2 C. Misha and Forest
- Codefroces 32C (简单模拟+数学)
- codefroces 723c Polycarp at the Radio
- Codefroces 750C New Year and Rating
- java【多线程】两个实现多线程的方法
- 最有用的Linux命令行使用技巧集锦
- Android 敏捷开发
- 2.3、单引号和双引号
- c++的动态内存分配
- 【Codefroces 717 C. Potions Homework】
- 关于LoadRunner压测过程中出现的error26601的解释
- 关闭Nginx的常用命令
- jsp和servlet
- 稀疏表示SR笔记
- 开始面人了
- ajax json数据返回
- phpcms 开启在线编辑模板
- AndroidManifest的理解