#D. 北辰英才大道

    Type: Default 1000ms 256MiB

北辰英才大道

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题面背景

在北辰校园里有一条道路,因人才众多,起名为英才大道,在道路两旁有一些科学家雕像,像钱学森,张家栋等。

题目描述

在英才大道上有 nn 个不同的雕像 ,我们想知道每两个雕像的距离之和。

输入格式

第一行两个整数 nn

第二行 nn 个整数 aia_i 表示每个雕像的位置

输出格式

输出一个整数表示距离之和

样例 #1

样例输入 #1

5
1 2 3 4 5

样例输出 #1

40

样例1解释

我们要计算 n×(n1)n \times (n-1) 个距离, 然后求和

数据范围

  • 对于 50%50\% 的数据,1n103,1ai1031\le n\le 10^3, 1 \le a_i \le 10^3
  • 对于 100%100\% 的数据,1n2×105,1ai1061\le n\le 2 \times 10^5, 1 \le a_i \le 10^6

2025北辰贺岁杯基础赛-(复现赛)

Not Attended
Status
Done
Rule
Ledo
Problem
6
Start at
2025-1-20 9:00
End at
2025-2-22 17:00
Duration
800 hour(s)
Host
Partic.
49