結果
| 問題 | No.1435 Mmm...... | 
| コンテスト | |
| ユーザー |  ninoinui | 
| 提出日時 | 2021-03-19 22:21:30 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 101 ms / 2,000 ms | 
| コード長 | 1,435 bytes | 
| コンパイル時間 | 6,360 ms | 
| コンパイル使用メモリ | 197,844 KB | 
| 最終ジャッジ日時 | 2025-01-19 18:45:41 | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 24 | 
ソースコード
#pragma GCC diagnostic warning "-Wextra"
#pragma GCC diagnostic warning "-Wshadow"
#include <bits/stdc++.h>
using namespace std;
template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }
template <class A, class B> ostream& operator<<(ostream& os, pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
static bool debug = false;
void dump() {}
template <class A, class... B> void dump(A&& a, B&&... b) { if (debug) cout << a << (sizeof...(b) ? ' ' : '\n'), dump(b...); }
template <class A> void dump1D(A& a) { if (debug) for (auto i = a.begin(); i != a.end(); i++) cout << *i << (next(i) != a.end() ? ' ' : '\n'); }
template <class A> void dump2D(A& a) { if (debug) for (auto i = a.begin(); i != a.end(); i++) dump1D(*i), cout << (next(i) != a.end() ? "" : "\n"); }
signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  // debug = true;
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  multiset<int> MS;
  auto f = [&]() {
    if ((int)MS.size() < 2) return false;
    return *prev(MS.end()) > *MS.begin() + *next(MS.begin());
  };
  long ans = 0;
  for (int l = 0, r = 0; r < N; r++) {
    MS.insert(A.at(r));
    while (f()) MS.erase(MS.find(A.at(l++)));
    dump(make_pair("l", l), make_pair("r", r));
    ans += r - l;
  }
  cout << ans << '\n';
}
            
            
            
        