結果

問題 No.1435 Mmm......
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-19 22:52:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 931 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 171,532 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-04-29 18:17:03
合計ジャッジ時間 4,232 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 41 ms
5,376 KB
testcase_07 AC 50 ms
5,376 KB
testcase_08 AC 57 ms
5,376 KB
testcase_09 AC 53 ms
5,376 KB
testcase_10 AC 46 ms
5,376 KB
testcase_11 AC 46 ms
5,376 KB
testcase_12 AC 42 ms
5,376 KB
testcase_13 AC 41 ms
5,376 KB
testcase_14 AC 31 ms
5,376 KB
testcase_15 AC 59 ms
5,376 KB
testcase_16 AC 49 ms
5,376 KB
testcase_17 AC 36 ms
5,376 KB
testcase_18 AC 60 ms
5,376 KB
testcase_19 AC 44 ms
5,376 KB
testcase_20 AC 55 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 98 ms
5,376 KB
testcase_24 AC 99 ms
5,376 KB
testcase_25 AC 99 ms
5,376 KB
testcase_26 AC 98 ms
5,376 KB
testcase_27 AC 98 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
using namespace std;
using ll = long long;
ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];

    multiset<int> st;
    int ans = 0;
    int l = 0;
    for (int r=0; r<n; ++r) {
        st.insert(a[r]);
        bool ok = false;
        while (true) {
            if (st.size() < 2) break;
            int m1 = *st.begin();
            int m2 = *next(st.begin(), 1);
            int M = *st.rbegin();
            if (m1 + m2 < M) {
                st.erase(st.find(a[l]));
                l++;
                continue;
            }
            ok = true;
            break;
        }
        if (ok) ans += r-l;
    }
    cout << ans << endl;
}
0