結果
問題 |
No.838 Noelちゃんと星々3
|
ユーザー |
![]() |
提出日時 | 2020-06-16 22:51:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,002 bytes |
コンパイル時間 | 5,937 ms |
コンパイル使用メモリ | 197,696 KB |
最終ジャッジ日時 | 2025-01-11 04:46:56 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 16 |
ソースコード
#include <bits/stdc++.h> #ifdef _DEBUG #include "debug.hpp" #else #define debug(...) #endif #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932; template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> y(n); rep(i, n) cin >> y[i]; sort(y.begin(), y.end()); vector<ll> x = y; x[0] = x[1]; REP(i, 1, n-1) { if(x[i+1]-x[i] <= x[i]-x[i-1]) x[i] = x[i+1]; else x[i] = x[i-1]; } if(x[n-1] != x[n-2]) x[n-1] = x[n-2]; ll ans = 0; rep(i, n) ans += abs(x[i]-y[i]); cout << ans << '\n'; return 0; }