# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200203 | wilwxk | Safety (NOI18_safety) | C++14 | 63 ms | 6008 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5+5;
int v[MAXN];
ll pre[MAXN], pos[MAXN];
int n, x;
int main() {
scanf("%d %d", &n, &x);
for(int i = 1; i <= n; i++) scanf("%d", &v[i]);
sort(v+1, v+1+n);
for(int i = 1; i <= n; i++) pre[i] = pre[i-1]+v[i];
for(int i = n; i >= 1; i--) pos[i] = pos[i+1]+v[i];
ll ans = 1e18;
for(int i = 1; i <= n; i++) {
ll val = v[i]*ll(i-1);
val -= pre[i-1];
val += pos[i+1];
val -= v[i]*ll(n-i);
ans = min(ans, val);
}
printf("%lld\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |