結果

問題 No.871 かえるのうた
ユーザー mmn15277198mmn15277198
提出日時 2021-10-09 12:18:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,314 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 98,072 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2023-10-10 21:51:07
合計ジャッジ時間 4,777 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 3 ms
4,356 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 3 ms
4,352 KB
testcase_12 AC 14 ms
4,352 KB
testcase_13 AC 4 ms
4,352 KB
testcase_14 AC 113 ms
6,480 KB
testcase_15 AC 112 ms
6,696 KB
testcase_16 AC 122 ms
6,424 KB
testcase_17 AC 101 ms
6,528 KB
testcase_18 AC 17 ms
4,348 KB
testcase_19 AC 116 ms
6,520 KB
testcase_20 AC 10 ms
4,348 KB
testcase_21 AC 44 ms
4,380 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 3 ms
4,352 KB
testcase_26 AC 6 ms
4,348 KB
testcase_27 AC 10 ms
4,356 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 35 ms
5,528 KB
testcase_30 AC 64 ms
5,736 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 53 ms
5,424 KB
testcase_33 AC 86 ms
6,572 KB
testcase_34 AC 20 ms
4,352 KB
testcase_35 AC 52 ms
5,280 KB
testcase_36 AC 72 ms
5,956 KB
testcase_37 AC 45 ms
4,380 KB
testcase_38 AC 99 ms
6,196 KB
testcase_39 AC 93 ms
6,140 KB
testcase_40 AC 30 ms
5,464 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 29 ms
5,456 KB
testcase_43 AC 2 ms
4,356 KB
testcase_44 AC 1 ms
4,352 KB
testcase_45 AC 2 ms
4,352 KB
testcase_46 AC 2 ms
4,352 KB
testcase_47 AC 1 ms
4,352 KB
testcase_48 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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--;

  long long mn = p[k].first;
  int mn_id = k;
  for (int i = k; i < n; i++) {
    if (mn > p[i].first) {
      mn = p[i].first;
      mn_id = i;
    }
  }

  long long mx = p[k].second;
  int mx_id = k;
  for (int i = k; i >= 0; i--) {
    if (mx < p[i].second) {
      mx = p[i].second;
      mx_id = i;
    }
  }

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