Submission #19725435


Source Code Expand

Copy
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int tmp(ll a,ll b){
	return a>b;
}
int main()
{
	ll n;
	cin>>n;
	ll a[n+1],sum[n+1],j=n,ans=0;
	for(ll i=1; i<=n; i++)
		cin>>a[i];
	sort(a+1,a+n+1,tmp);
	for(ll i=1; i<=n; i++){
		sum[i]=j;
		j--;
	}
	for(ll i=1; i<=n; i++){
		j++;
		sum[i]-=j;
	}
	for(ll i=1; i<=n; i++)	ans+=a[i]*sum[i];
	cout<<ans;
	return 0;
}

Submission Info

Submission Time
Task D - Sum of difference
User LCN100324
Language C++ (GCC 9.2.1)
Score 400
Code Size 410 Byte
Status AC
Exec Time 87 ms
Memory 6720 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 7 ms 3548 KB
max_01.txt AC 79 ms 6632 KB
max_02.txt AC 70 ms 6720 KB
random_01.txt AC 86 ms 6628 KB
random_02.txt AC 86 ms 6492 KB
random_03.txt AC 86 ms 6684 KB
random_04.txt AC 82 ms 6696 KB
random_05.txt AC 86 ms 6540 KB
random_06.txt AC 86 ms 6548 KB
random_07.txt AC 85 ms 6652 KB
random_08.txt AC 85 ms 6496 KB
random_09.txt AC 83 ms 6536 KB
random_10.txt AC 84 ms 6616 KB
random_11.txt AC 84 ms 6688 KB
random_12.txt AC 82 ms 6516 KB
random_13.txt AC 85 ms 6664 KB
random_14.txt AC 85 ms 6676 KB
random_15.txt AC 84 ms 6652 KB
random_16.txt AC 86 ms 6632 KB
random_17.txt AC 83 ms 6544 KB
random_18.txt AC 86 ms 6668 KB
random_19.txt AC 87 ms 6672 KB
random_20.txt AC 82 ms 6620 KB
sample_01.txt AC 3 ms 3528 KB
sample_02.txt AC 2 ms 3528 KB