結果

問題 No.871 かえるのうた
ユーザー QCFiumQCFium
提出日時 2019-08-30 21:46:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 690 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 172,648 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-30 10:45:38
合計ジャッジ時間 3,204 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	assert(scanf("%d", &n) == 1);
	return n;
}
int64_t rs64() {
	int64_t n;
	assert(scanf("%" SCNd64, &n) == 1);
	return n;
}

int main () {
	int n = ri();
	int k = ri() - 1;
	struct F {
		int64_t x;
		int64_t a;
		int id;
	};
	int64_t x[n];
	int64_t a[n];
	for (int i = 0; i < n; i++) x[i] = rs64();
	for (int i = 0; i < n; i++) a[i] = rs64();
	
	int l = k, r = k;
	std::queue<int> que;
	que.push(k);
	while (que.size()) {
		int cur = que.front();
		que.pop();
		while (l && x[l - 1] >= x[cur] - a[cur]) l--, que.push(l);
		while (r + 1 < n && x[r + 1] <= x[cur] + a[cur]) r++, que.push(r);
	}
	std::cout << r - l + 1 << std::endl;
	
	return 0;
}
0