結果
問題 |
No.837 Noelちゃんと星々2
|
ユーザー |
![]() |
提出日時 | 2019-06-15 02:48:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 938 bytes |
コンパイル時間 | 1,835 ms |
コンパイル使用メモリ | 172,288 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-11 14:19:56 |
合計ジャッジ時間 | 2,653 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> Y(N); for (int i = 0; i < N; i++) { cin >> Y[i]; } if (N == 2) { if (Y[0] == Y[1]) { cout << 1 << "\n"; } else { cout << 0 << "\n"; } return 0; } sort(Y.begin(), Y.end()); if (Y[0] == Y[N - 1]) { cout << "1\n"; return 0; } if (Y[0] == Y[N - 2]) { cout << "0\n"; return 0; } ll ans = pow(10, 15); ll S[N + 1]{}; for (int i = 0; i < N; i++) { S[i + 1] += S[i] + Y[i]; } for (int i = 0; i < N - 1; i++) { int m1 = i / 2; int m2 = (N + i) / 2; ll cost = (m1 + 1) * Y[m1] - S[m1 + 1] + S[i + 1] - S[m1 + 1] - (i - m1) * Y[m1]; cost += (m2 - i) * Y[m2] - (S[m2 + 1] - S[i + 1]) + (S[N] - S[m2 + 1]) - (N - 1- m2) * Y[m2]; ans = min(ans, cost); } cout << ans << "\n"; return 0; }