Submission #71414651


Source Code Expand

#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define COUT(num,len) cout << fixed << setprecision(len) << num;
#define ALL(x) (x).begin(), (x).end()
#define coutY cout << "Yes" << endl;
#define coutN cout << "No" << endl;
#define arrIn(arr, start, N) for (int i = (start); i < (N); ++i) cin >> arr[i];
#define arrOut(arr, start, N) for  (int i = (start); i < (N); ++i) { cout << arr[i] <<" "; } cout << endl;
#define arrCopy(arr1,arr2, start, N) for (int i = (start); i < (N); ++i) arr2[i]= arr1[i];
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }
void YN(bool tf) { cout << (tf ? "YES\n" : "NO\n"); }
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string abc="abcdefghijklmnopqrstuvwxyz";

//cout << fixed << setprecision(20) <<

int gcd(int a, int b){ //最大公約数
  if(a%b == 0){
    return b;
  }else{
    return gcd(b, a%b);
  }
}

int lcm(int a, int b){ //最小公倍数
  return a*b / gcd(a, b);
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<ll> A(N);
  arrIn(A,0,N);
  sort(ALL(A));
  reverse(ALL(A));
  ll ans=0;
  for(ll i=0;i<N;i++){
    ans+=A[i]*(N-1-2*i);
  }
  cout << ans << endl;
 
  return 0;
}

Submission Info

Submission Time
Task D - Sum of difference
User UT0911
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1344 Byte
Status AC
Exec Time 26 ms
Memory 4772 KiB

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 1 ms 3496 KiB
max_01.txt AC 18 ms 4560 KiB
max_02.txt AC 12 ms 4604 KiB
random_01.txt AC 25 ms 4592 KiB
random_02.txt AC 25 ms 4672 KiB
random_03.txt AC 25 ms 4592 KiB
random_04.txt AC 25 ms 4652 KiB
random_05.txt AC 25 ms 4608 KiB
random_06.txt AC 25 ms 4624 KiB
random_07.txt AC 25 ms 4528 KiB
random_08.txt AC 25 ms 4600 KiB
random_09.txt AC 25 ms 4672 KiB
random_10.txt AC 26 ms 4560 KiB
random_11.txt AC 25 ms 4596 KiB
random_12.txt AC 25 ms 4772 KiB
random_13.txt AC 26 ms 4540 KiB
random_14.txt AC 25 ms 4680 KiB
random_15.txt AC 25 ms 4624 KiB
random_16.txt AC 25 ms 4684 KiB
random_17.txt AC 25 ms 4672 KiB
random_18.txt AC 25 ms 4592 KiB
random_19.txt AC 25 ms 4680 KiB
random_20.txt AC 25 ms 4688 KiB
sample_01.txt AC 1 ms 3420 KiB
sample_02.txt AC 1 ms 3620 KiB