結果

問題 No.871 かえるのうた
ユーザー misora192
提出日時 2020-05-13 08:33:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 728 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 170,736 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-14 15:26:16
合計ジャッジ時間 3,703 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;
	k--;

	vector<ll> x(n), a(n);
	rep(i, n) cin >> x[i];
	rep(i, n) cin >> a[i];

	int ans = 1;
	ll mx = x[k] + a[k];
	for(int i = k + 1; i < n; i++){
		if(x[i] > mx) break;
		ans++;
		chmax(mx, x[i] + a[i]);
	}

	ll mn = x[k] - a[k];
	for(int i = k - 1; i >= 0; i--){
		if(x[i] < mn) break;
		ans++;
		chmin(mn, x[i] - a[i]);
	}

	cout << ans << endl;
}
0