A. 暮雪少年与数组平衡术

    传统题 1000ms 256MiB

暮雪少年与数组平衡术

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Background

Welcome to XJS Round 3 - Div3! In this contest, you will embark on an adventure with the young boy Muxue and help him solve a series of problems. This contest is jointly hosted by XJSOJ & XieMa Coduck (MarsOJ) , and this is the main venue.

Problem Description

Muxue has an integer array of length nn. He wants to make all elements in the array equal with the minimum number of operations. The only operation allowed is: choose any element in the array and increase its value by 1.

Muxue would like to know the minimum number of such operations required to make all elements in the array equal. Note that he can only increase the values of the elements, not decrease them.

Please write a program to help Muxue solve this problem.

Input Format

  • The first line contains an integer n(1n105)n (1 \leqslant n \leqslant 10^5), the length of the array.
  • The second line contains nn integers $a_1, a_2, \cdots, a_n (1 \leqslant a_i \leqslant 10^9)$, the elements of the array.

Output Format

A single integer, representing the minimum number of operations required to make all elements equal.

Sample Input/Output #1

Input #1

5
1 2 3 4 5

Output #1

10

Sample Input/Output #2

Input #2

3
5 5 5

Output #2

0

Explanation

Explanation of Sample 1: Changing all elements to 5 requires 0+1+2+3+4=100+1+2+3+4=10 operations.

This problem uses Subtask bundled testing.

Subtask 1 (25 points): 1n301 \leq n \leq 30.

Subtask 2 (25 points): 1n1001 \leq n \leq 100.

Subtask 3 (25 points): 1n100001 \leq n \leq 10000.

Subtask 4 (25 points): 1n1000001 \leq n \leq 100000.

【XJS-C5-Div3】XJSOI 春节大月赛 Round 3 & 勰码可达鸭合作赛 Round 1

未参加
状态
已结束
规则
IOI
题目
5
开始于
2026-2-14 0:00
结束于
2026-2-17 0:00
持续时间
4 小时
主持人
参赛人数
7