結果

問題 No.871 かえるのうた
コンテスト
ユーザー mmn15277198
提出日時 2021-10-09 11:57:32
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 864 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 626 ms
コンパイル使用メモリ 112,580 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2026-04-03 18:05:39
合計ジャッジ時間 4,192 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

int main() {
  int n , k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  vector<pair<long long , long long> > p(n);

  for (int i = 0; i < n; i++) {
    p[i]= make_pair(a[i] - x[i] , a[i] + x[i]);
  }

  k--;
  vector<int> cnt(n , 0);
  cnt[k] = 1;
  for (int i = k; i < n - 1; i++) {
    if (p[i].second >= a[i + 1]) cnt[i + 1] = cnt[i];
  }
  for (int i = k; i >= 1; i--) {
    if (p[i].first <= a[i - 1]) cnt[i - 1] = cnt[i];
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += cnt[i] > 0;
  }
  cout << ans << endl;
  return 0;
}
0