結果

問題 No.871 かえるのうた
ユーザー mmn15277198
提出日時 2021-10-09 11:57:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 864 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 100,616 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-26 19:33:45
合計ジャッジ時間 5,342 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#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