結果

問題 No.871 かえるのうた
ユーザー jxkoko
提出日時 2019-10-26 00:57:25
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,081 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 86,684 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 12:02:15
合計ジャッジ時間 3,989 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
#include <set> 
using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
typedef pair<pair<int, int>, int> PP;

const ll INF = 1e15;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(void) {
	int N, K; cin >> N >> K; K--;
	vector<ll> X(N), A(N);
	for (int i = 0; i < N; i++) cin >> X[i];
	for (int i = 0; i < N; i++) cin >> A[i];
	int l, r, lX, rX;
	bool update = true;
	l = r = K;
	lX = X[K] - A[K]; rX = X[K] + A[K];
	while (update) {
		update = false;
		while (r < N && X[r] <= rX) {
			if (rX < X[r] + A[r]) {
				rX = X[r] + A[r];
				update = true; 
			}
			if (X[r] - A[r] < lX) {
				lX = X[r] - A[r];
				update = true;
			}
			r++;
		}
		while (0 <= l && lX <= X[l]) {
			if (X[l] - A[l] < lX) {
				lX = X[l] - A[l];
				update = true;
			}
			if (rX < X[l] + A[l]) {
				rX = X[l] + A[l];
				update = true;
			}
			l--;
		}
	}
	cout << r - l - 1 << endl;
}
0