【Codefroces 717 C. Potions Homework】

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值