結果

問題 No.871 かえるのうた
ユーザー data9824data9824
提出日時 2019-09-14 03:38:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 500 ms
コンパイル使用メモリ 62,172 KB
実行使用メモリ 4,748 KB
最終ジャッジ日時 2023-08-20 09:28:43
合計ジャッジ時間 3,966 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,388 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 15 ms
4,384 KB
testcase_13 AC 4 ms
4,384 KB
testcase_14 AC 111 ms
4,748 KB
testcase_15 AC 112 ms
4,644 KB
testcase_16 AC 121 ms
4,520 KB
testcase_17 AC 99 ms
4,380 KB
testcase_18 AC 18 ms
4,384 KB
testcase_19 AC 114 ms
4,640 KB
testcase_20 AC 10 ms
4,380 KB
testcase_21 AC 43 ms
4,384 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 10 ms
4,384 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 35 ms
4,384 KB
testcase_30 AC 63 ms
4,384 KB
testcase_31 AC 3 ms
4,384 KB
testcase_32 AC 52 ms
4,380 KB
testcase_33 AC 83 ms
4,648 KB
testcase_34 AC 20 ms
4,380 KB
testcase_35 AC 51 ms
4,384 KB
testcase_36 AC 72 ms
4,384 KB
testcase_37 AC 45 ms
4,388 KB
testcase_38 AC 98 ms
4,380 KB
testcase_39 AC 92 ms
4,384 KB
testcase_40 AC 29 ms
4,384 KB
testcase_41 AC 1 ms
4,384 KB
testcase_42 AC 29 ms
4,384 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,384 KB
testcase_45 AC 3 ms
4,384 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,384 KB
testcase_48 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<long long> x(n), a(n);
	for (int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	long long frontX = x[k - 1] - a[k - 1];
	long long backX = x[k - 1] + a[k - 1];
	int frontIndex = k - 1 - 1;
	int backIndex = k - 1 + 1;
	for (;;) {
		bool newlySung = false;
		if (frontIndex >= 0 && frontX <= x[frontIndex]) {
			frontX = min(frontX, x[frontIndex] - a[frontIndex]);
			backX = max(backX, x[frontIndex] + a[frontIndex]);
			--frontIndex;
			newlySung = true;
		}
		if (backIndex < n && x[backIndex] <= backX) {
			backX = max(backX, x[backIndex] + a[backIndex]);
			frontX = min(frontX, x[backIndex] - a[backIndex]);
			++backIndex;
			newlySung = true;
		}
		if (!newlySung) {
			break;
		}
	}
	cout << (backIndex - frontIndex - 2 + 1) << endl;
	return 0;
}
0