結果

問題 No.1687 What the Heck?
ユーザー naskya
提出日時 2021-09-29 11:16:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 74,724 KB
最終ジャッジ日時 2025-01-24 18:38:51
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int N;
  std::cin >> N;

  std::vector<int> round(N + 1);
  for (int i = 0; i < N; ++i) {
    int p;
    std::cin >> p;
    round[p] = i + 1;
  }

  long long ans = 0, sum = static_cast<long long>(N) * (N + 1) / 2;

  for (int i = N; i > 0; --i) {
    sum -= round[i];
    ans = std::max(ans, sum - round[i]);
  }

  std::cout << ans << '\n';
}
0