QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#23926. Age Difference

Statistics

Problem Statement

In JOI City, there are $N$ residents numbered from $1$ to $N$, and the age of resident $i$ ($1 \le i \le N$) is $A_i$ years old.

The ages $A_1, A_2, \dots, A_N$ of the residents of JOI City are given. Write a program to find, for each $i = 1, 2, \dots, N$, the maximum age difference between resident $i$ and the other residents.

Constraints

  • $2 \le N \le 250000$.
  • $0 \le A_i \le 10^9$ ($1 \le i \le N$).
  • All input values are integers.

Subtasks

  1. ($25$ points) $N = 2$.
  2. ($30$ points) $N \le 1000$.
  3. ($45$ points) No additional constraints.

Input

The input is given in the following format:

$N$ $A_1 \ A_2 \ \dots \ A_N$

Output

Output $N$ lines. On the $i$-th line ($1 \le i \le N$), output the maximum age difference between resident $i$ and the other residents.

Sample Input and Output

Sample Input 1

3
13 15 20

Sample Output 1

7
5
7
  • The age differences between resident $1$ and residents $2, 3$ are $2, 7$ years, respectively. Since their maximum value is $7$ years, output $7$ on the $1$-st line.
  • The age differences between resident $2$ and residents $1, 3$ are $2, 5$ years, respectively. Since their maximum value is $5$ years, output $5$ on the $2$-nd line.
  • The age differences between resident $3$ and residents $1, 2$ are $7, 5$ years, respectively. Since their maximum value is $7$ years, output $7$ on the $3$-rd line.

This sample input satisfies the constraints of Subtasks $2, 3$.

Sample Input 2

2
100 100

Sample Output 2

0
0
  • The age difference between resident $1$ and resident $2$ is $0$ years. Therefore, output $0$ on the $1$-st line.
  • The age difference between resident $2$ and resident $1$ is $0$ years. Therefore, output $0$ on the $2$-nd line.

This sample input satisfies the constraints of all subtasks.

Sample Input 3

10
440894064 101089692 556439322 34369336 98417847 216265879 623843484 554560874 247445405 718003331

Sample Output 3

406524728
616913639
522069986
683633995
619585484
501737452
589474148
520191538
470557926
683633995

This sample input satisfies the constraints of Subtasks $2, 3$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.