Submission #10312105
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n"
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
int main() {
init();
int n; cin >> n;
VL x(n); cin >> x;
SORT(x);
ll ans = 0;
FOR(i, 1, n) {
ans += x[i] * ll(i) - x[i - 1];
x[i] += x[i - 1];
}
cout << ans << "\n";
}
Submission Info
Submission Time |
|
Task |
C - Pair Distance |
User |
first_vil |
Language |
C++14 (GCC 5.4.1) |
Score |
300 |
Code Size |
2272 Byte |
Status |
AC |
Exec Time |
17 ms |
Memory |
1024 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, s1.txt, s2.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
1 ms |
256 KB |
02.txt |
AC |
1 ms |
256 KB |
03.txt |
AC |
2 ms |
256 KB |
04.txt |
AC |
1 ms |
256 KB |
05.txt |
AC |
1 ms |
256 KB |
06.txt |
AC |
2 ms |
256 KB |
07.txt |
AC |
2 ms |
256 KB |
08.txt |
AC |
2 ms |
256 KB |
09.txt |
AC |
2 ms |
256 KB |
10.txt |
AC |
2 ms |
256 KB |
11.txt |
AC |
16 ms |
1024 KB |
12.txt |
AC |
17 ms |
1024 KB |
13.txt |
AC |
17 ms |
1024 KB |
14.txt |
AC |
16 ms |
1024 KB |
15.txt |
AC |
17 ms |
1024 KB |
16.txt |
AC |
17 ms |
1024 KB |
17.txt |
AC |
17 ms |
1024 KB |
18.txt |
AC |
16 ms |
1024 KB |
19.txt |
AC |
17 ms |
1024 KB |
20.txt |
AC |
17 ms |
1024 KB |
21.txt |
AC |
16 ms |
1024 KB |
22.txt |
AC |
17 ms |
1024 KB |
23.txt |
AC |
17 ms |
1024 KB |
24.txt |
AC |
17 ms |
1024 KB |
25.txt |
AC |
16 ms |
1024 KB |
s1.txt |
AC |
1 ms |
256 KB |
s2.txt |
AC |
1 ms |
256 KB |