Submission #19722794


Source Code Expand

Copy
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		long[] A = new long[N];
		long ans = 0;
		long sum = 0;
		for(int i=0 ; i<N ; i++) {
			A[i] = Long.parseLong(sc.next());
			sum += A[i];
		}
		Arrays.parallelSort(A);
		long sumA = 0;
		for(int i=0 ; i<N ; i++) {
			sumA += A[i];
			ans += sum;
			ans -= sumA;
			ans -= A[i]*(N-i-1);
			
		}
		System.out.println(ans);
	}
}

Submission Info

Submission Time
Task D - Sum of difference
User muna
Language Java (OpenJDK 11.0.6)
Score 400
Code Size 544 Byte
Status AC
Exec Time 570 ms
Memory 61476 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 25
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand_01.txt, max_01.txt, max_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand_01.txt AC 108 ms 35404 KB
max_01.txt AC 441 ms 60160 KB
max_02.txt AC 443 ms 60184 KB
random_01.txt AC 494 ms 60356 KB
random_02.txt AC 433 ms 61476 KB
random_03.txt AC 506 ms 60520 KB
random_04.txt AC 510 ms 61048 KB
random_05.txt AC 521 ms 60552 KB
random_06.txt AC 470 ms 60412 KB
random_07.txt AC 492 ms 60484 KB
random_08.txt AC 456 ms 60556 KB
random_09.txt AC 514 ms 60540 KB
random_10.txt AC 479 ms 60232 KB
random_11.txt AC 504 ms 60676 KB
random_12.txt AC 570 ms 60500 KB
random_13.txt AC 490 ms 60064 KB
random_14.txt AC 545 ms 60384 KB
random_15.txt AC 493 ms 60312 KB
random_16.txt AC 471 ms 60432 KB
random_17.txt AC 522 ms 60816 KB
random_18.txt AC 501 ms 60684 KB
random_19.txt AC 461 ms 60256 KB
random_20.txt AC 502 ms 60564 KB
sample_01.txt AC 105 ms 35632 KB
sample_02.txt AC 104 ms 35444 KB