Submission #19724568


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=2e5+4;
ll a[MAXN],sum[MAXN];
int main()
 {
    int n,i;
    cin>>n;
    for(i=1;i<=n;i++) 
	{
        cin>>a[i];
    }
    sort(a+1,a+n+1,greater<int>());
    for(i=1;i<=n;i++) 
	{
        sum[i]=sum[i-1]+a[i]; 
    }
    ll ans=0;
    for(i=1;i<n;i++)
	{
        ans+=sum[n-i]-(sum[n]-sum[i]);
    }
    cout<<ans<<"\n";
    return 0;
}

Submission Info

Submission Time
Task D - Sum of difference
User AliceYZ
Language C++ (GCC 9.2.1)
Score 400
Code Size 444 Byte
Status AC
Exec Time 83 ms
Memory 6724 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 5 ms 3496 KB
max_01.txt AC 78 ms 6612 KB
max_02.txt AC 68 ms 6540 KB
random_01.txt AC 78 ms 6480 KB
random_02.txt AC 82 ms 6632 KB
random_03.txt AC 81 ms 6632 KB
random_04.txt AC 81 ms 6656 KB
random_05.txt AC 80 ms 6612 KB
random_06.txt AC 80 ms 6656 KB
random_07.txt AC 83 ms 6544 KB
random_08.txt AC 81 ms 6724 KB
random_09.txt AC 78 ms 6536 KB
random_10.txt AC 80 ms 6660 KB
random_11.txt AC 81 ms 6480 KB
random_12.txt AC 82 ms 6660 KB
random_13.txt AC 83 ms 6540 KB
random_14.txt AC 79 ms 6668 KB
random_15.txt AC 81 ms 6536 KB
random_16.txt AC 83 ms 6536 KB
random_17.txt AC 79 ms 6724 KB
random_18.txt AC 82 ms 6544 KB
random_19.txt AC 82 ms 6724 KB
random_20.txt AC 81 ms 6632 KB
sample_01.txt AC 2 ms 3516 KB
sample_02.txt AC 2 ms 3364 KB