結果

問題 No.1435 Mmm......
ユーザー SSRSSSRS
提出日時 2021-03-19 22:22:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 171,408 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-29 17:25:05
合計ジャッジ時間 4,311 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 46 ms
5,376 KB
testcase_07 AC 56 ms
5,376 KB
testcase_08 AC 65 ms
5,376 KB
testcase_09 AC 60 ms
5,376 KB
testcase_10 AC 52 ms
5,376 KB
testcase_11 AC 52 ms
5,376 KB
testcase_12 AC 48 ms
5,376 KB
testcase_13 AC 48 ms
5,376 KB
testcase_14 AC 36 ms
5,376 KB
testcase_15 AC 68 ms
5,376 KB
testcase_16 AC 56 ms
5,376 KB
testcase_17 AC 41 ms
5,376 KB
testcase_18 AC 68 ms
5,376 KB
testcase_19 AC 51 ms
5,376 KB
testcase_20 AC 62 ms
5,376 KB
testcase_21 AC 145 ms
13,312 KB
testcase_22 AC 138 ms
10,624 KB
testcase_23 AC 107 ms
5,376 KB
testcase_24 AC 105 ms
5,376 KB
testcase_25 AC 106 ms
5,376 KB
testcase_26 AC 106 ms
5,376 KB
testcase_27 AC 106 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  multiset<int> st;
  st.insert(a[0]);
  int r = 1;
  long long ans = 0;
  for (int l = 0; l < N - 1; l++){
    while (r < N){
      st.insert(a[r]);
      int m1 = *st.begin();
      int m2 = *next(st.begin());
      int M = *prev(st.end());
      if (M > m1 + m2){
        st.erase(st.find(a[r]));
        break;
      } else {
        r++;
      }
    }
    ans += r - l - 1;
    st.erase(st.find(a[l]));
  }
  cout << ans << endl;
}
0