結果
問題 | No.837 Noelちゃんと星々2 |
ユーザー |
|
提出日時 | 2019-06-14 21:34:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 806 bytes |
コンパイル時間 | 1,951 ms |
コンパイル使用メモリ | 172,132 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-11 14:12:03 |
合計ジャッジ時間 | 3,235 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--) using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); if (a[0] == a[n - 1]) { cout << 1 << '\n'; return 0; } vector<ll> sum(n + 1); rep(i, n) sum[i + 1] = sum[i] + a[i]; ll ans = 1e18; for (int i = 1; i < n; i++) { int x = i / 2; int y = (n - i) / 2 + i; ll cost = 0; cost += a[x]*x - (sum[x] - sum[0]); cost += (sum[i] - sum[x]) - a[x]*(i-x); cost += a[y]*(y-i) - (sum[y] - sum[i]); cost += (sum[n] - sum[y]) - a[y]*(n-y); ans = min(ans, cost); } cout << ans << '\n'; }