結果

問題 No.2304 Distinct Elements
ユーザー SSRSSSRS
提出日時 2023-05-12 21:53:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 3,000 ms
コード長 971 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 177,744 KB
実行使用メモリ 7,144 KB
最終ジャッジ日時 2024-05-06 11:42:41
合計ジャッジ時間 6,353 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 59 ms
7,112 KB
testcase_05 AC 59 ms
6,912 KB
testcase_06 AC 59 ms
7,028 KB
testcase_07 AC 61 ms
7,016 KB
testcase_08 AC 62 ms
7,016 KB
testcase_09 AC 116 ms
7,140 KB
testcase_10 AC 117 ms
7,020 KB
testcase_11 AC 115 ms
7,016 KB
testcase_12 AC 113 ms
7,016 KB
testcase_13 AC 112 ms
7,144 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 71 ms
6,620 KB
testcase_30 AC 8 ms
5,376 KB
testcase_31 AC 58 ms
5,400 KB
testcase_32 AC 90 ms
6,676 KB
testcase_33 AC 9 ms
5,376 KB
testcase_34 AC 92 ms
6,832 KB
testcase_35 AC 103 ms
6,780 KB
testcase_36 AC 7 ms
5,376 KB
testcase_37 AC 21 ms
5,376 KB
testcase_38 AC 68 ms
7,120 KB
testcase_39 AC 69 ms
7,144 KB
testcase_40 AC 37 ms
6,492 KB
testcase_41 AC 20 ms
5,376 KB
testcase_42 AC 48 ms
7,016 KB
testcase_43 AC 100 ms
7,144 KB
testcase_44 AC 81 ms
6,576 KB
testcase_45 AC 57 ms
5,376 KB
testcase_46 AC 46 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 78 ms
7,012 KB
testcase_50 AC 90 ms
7,016 KB
testcase_51 AC 88 ms
7,016 KB
testcase_52 AC 66 ms
7,012 KB
testcase_53 AC 72 ms
7,016 KB
testcase_54 AC 56 ms
7,140 KB
testcase_55 AC 53 ms
7,144 KB
testcase_56 AC 52 ms
7,016 KB
testcase_57 AC 79 ms
7,016 KB
testcase_58 AC 77 ms
7,144 KB
testcase_59 AC 57 ms
7,012 KB
testcase_60 AC 1 ms
5,376 KB
testcase_61 AC 2 ms
5,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