結果

問題 No.1435 Mmm......
ユーザー 夜
提出日時 2021-03-22 22:05:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 849 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 96,204 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-05-03 11:04:26
合計ジャッジ時間 4,564 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 40 ms
5,376 KB
testcase_07 AC 49 ms
5,376 KB
testcase_08 AC 57 ms
5,376 KB
testcase_09 AC 53 ms
5,376 KB
testcase_10 AC 47 ms
5,376 KB
testcase_11 AC 44 ms
5,376 KB
testcase_12 AC 43 ms
5,376 KB
testcase_13 AC 40 ms
5,376 KB
testcase_14 AC 31 ms
5,376 KB
testcase_15 AC 59 ms
5,376 KB
testcase_16 AC 50 ms
5,376 KB
testcase_17 AC 35 ms
5,376 KB
testcase_18 AC 60 ms
5,376 KB
testcase_19 AC 44 ms
5,376 KB
testcase_20 AC 54 ms
5,376 KB
testcase_21 AC 143 ms
13,568 KB
testcase_22 AC 90 ms
10,752 KB
testcase_23 AC 97 ms
5,376 KB
testcase_24 AC 98 ms
5,376 KB
testcase_25 AC 97 ms
5,376 KB
testcase_26 AC 99 ms
5,376 KB
testcase_27 AC 97 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int a[200020];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	multiset<int> st;
	st.insert(a[0]);
	st.insert(a[1]);
	int r = 1;
	long long ans = 0;
	for (int l = 0; l < n - 1; l++) {
		int m1 = *st.begin() + *(++st.begin());
		int m = *st.rbegin();
		while (r < n && m1 >= m) {
			r++;
			if (r == n)break;
			st.insert(a[r]);
			m1 = *st.begin() + *(++st.begin());
			m = *st.rbegin();
		}
		ans += r - l - 1;
		if (l == r) {
			r++;
			st.insert(a[r]);
		}
		else {
			st.erase(st.find(a[l]));
		}
	}
	cout << ans << endl;
}
0