結果
| 問題 |
No.871 かえるのうた
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-01 20:25:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 130 ms / 2,000 ms |
| コード長 | 1,853 bytes |
| コンパイル時間 | 1,495 ms |
| コンパイル使用メモリ | 138,464 KB |
| 最終ジャッジ日時 | 2025-01-07 16:16:43 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 49 |
ソースコード
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>
using namespace std;
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}
using LL = long long;
//------------------------------------------
//------------------------------------------
int main() {
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];
LL lk = K;
LL rk = K;
LL ld = X[lk] - A[lk];
LL rd = X[rk] + A[rk];
bool update = false;
while (true) {
update = false;
while (lk - 1 >= 0 && ld <= X[lk - 1]) {
lk--;
ld = min(ld, X[lk] - A[lk]);
rd = max(rd, X[lk] + A[lk]);
update = true;
}
while (rk + 1 <= N - 1 && rd >= X[rk + 1]) {
rk++;
ld = min(ld, X[rk] - A[rk]);
rd = max(rd, X[rk] + A[rk]);
update = true;
}
if (!update) break;
}
cout << rk - lk + 1 << endl;
}