結果
問題 |
No.1391 ±1 Abs Sum
|
ユーザー |
![]() |
提出日時 | 2021-02-12 23:44:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 1,232 bytes |
コンパイル時間 | 1,569 ms |
コンパイル使用メモリ | 166,416 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 01:37:20 |
合計ジャッジ時間 | 3,556 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; ll A[200001]; rep(i, N) cin >> A[i]; A[N] = 2e18; int L = 0, R = K; ll kari = 0; rep(i, R) kari += A[i]; for (int i = R; i < N; i++) kari -= A[i]; ll kotae = 1e18; chmin(kotae, kari - A[0] * (R + R + L + L - N)); ce(kotae); rep1(i, N - 1) { kari -= 2 * A[i - 1]; ll X = A[i]; while (X - A[L] > A[R] - X) { kari += 2 * A[L]; kari += 2 * A[R]; L++; R++; } //cesp(L); //cesp(R); //cesp(kari); //ce(kari - X * (R + R - i - i + L + L - N)); chmin(kotae, kari - X * (R + R - i - i + L + L - N)); } co(kotae); Would you please return 0; }