結果
問題 |
No.1391 ±1 Abs Sum
|
ユーザー |
![]() |
提出日時 | 2021-02-12 22:27:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 765 bytes |
コンパイル時間 | 1,034 ms |
コンパイル使用メモリ | 92,336 KB |
最終ジャッジ日時 | 2025-01-18 18:58:27 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 WA * 13 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; k = n - k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll r = 1LL << 60; for (int h = 0; h < 2; h++) { int x = a[min(k + n / 2, n - 1)]; ll t = 0; for (int i = 0; i < n; i++) { t += abs(x - a[i]) * (i < k ? -1 : 1); } r = min(r, t); reverse(a.begin(), a.end()); for (int i = 0; i < n; i++) { a[i] *= -1; } } cout << r << endl; return 0; }