結果

問題 No.2304 Distinct Elements
ユーザー SSRSSSRS
提出日時 2023-05-12 21:53:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 3,000 ms
コード長 971 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 176,204 KB
実行使用メモリ 6,896 KB
最終ジャッジ日時 2023-08-19 04:31:07
合計ジャッジ時間 7,702 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 69 ms
6,632 KB
testcase_05 AC 69 ms
6,660 KB
testcase_06 AC 69 ms
6,752 KB
testcase_07 AC 68 ms
6,656 KB
testcase_08 AC 69 ms
6,684 KB
testcase_09 AC 122 ms
6,664 KB
testcase_10 AC 122 ms
6,632 KB
testcase_11 AC 121 ms
6,632 KB
testcase_12 AC 124 ms
6,612 KB
testcase_13 AC 122 ms
6,820 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 79 ms
6,332 KB
testcase_30 AC 8 ms
4,376 KB
testcase_31 AC 66 ms
4,984 KB
testcase_32 AC 95 ms
6,348 KB
testcase_33 AC 9 ms
4,376 KB
testcase_34 AC 98 ms
6,376 KB
testcase_35 AC 110 ms
6,480 KB
testcase_36 AC 7 ms
4,380 KB
testcase_37 AC 24 ms
4,380 KB
testcase_38 AC 75 ms
6,640 KB
testcase_39 AC 77 ms
6,580 KB
testcase_40 AC 42 ms
6,236 KB
testcase_41 AC 22 ms
4,560 KB
testcase_42 AC 57 ms
6,656 KB
testcase_43 AC 111 ms
6,612 KB
testcase_44 AC 88 ms
6,284 KB
testcase_45 AC 62 ms
4,892 KB
testcase_46 AC 48 ms
4,832 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 85 ms
6,748 KB
testcase_50 AC 95 ms
6,632 KB
testcase_51 AC 95 ms
6,748 KB
testcase_52 AC 74 ms
6,732 KB
testcase_53 AC 77 ms
6,632 KB
testcase_54 AC 64 ms
6,664 KB
testcase_55 AC 61 ms
6,760 KB
testcase_56 AC 60 ms
6,636 KB
testcase_57 AC 87 ms
6,896 KB
testcase_58 AC 85 ms
6,632 KB
testcase_59 AC 65 ms
6,688 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000000;
struct slope_trick{
  long long mn;
  priority_queue<long long> L;
  priority_queue<long long, vector<long long>, greater<long long>> R;
  slope_trick(){
    mn = 0;
    L.push(-INF);
    R.push(INF);
  }
  long long get_min(){
    return mn;
  }
  void add_right(long long a){
    mn += max(L.top() - a, (long long) 0);
    L.push(a);
    R.push(L.top());
    L.pop();
  }
  void add_left(long long a){
    mn += max(a - R.top(), (long long) 0);
    R.push(a);
    L.push(R.top());
    R.pop();
  }
};
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++){
    A[i] -= i;
  }
  slope_trick f;
  for (int i = 0; i < N; i++){
    f.add_left(A[i]);
    f.add_right(A[i]);
    while (!f.R.empty()){
      f.R.pop();
    }
    f.R.push(INF);
  }
  cout << f.mn << endl;
}
0