結果

問題 No.871 かえるのうた
ユーザー cureskol
提出日時 2019-08-31 12:38:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 1,390 ms
コンパイル使用メモリ 168,812 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-30 10:53:56
合計ジャッジ時間 4,284 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
const int INF=1e9;
//const int MOD=998244353;
const long long LINF=1e18;
#define int long long
//template
//main
signed main(){
  int N,K;cin>>N>>K;
  std::vector<int> x(N+2),a(N+2);
  for(int i=0;i<N;i++)cin>>x[i+1];
  for(int i=0;i<N;i++)cin>>a[i+1];
  x[0]=-LINF;x[N+1]=LINF;a[0]=a[N+1]=0;
  int rnow=K,lnow=K;//声を出した右端と左端
  int left=x[K]-a[K],right=x[K]+a[K];
  bool f=true;
  while(f){
    f=false;
    if(x[rnow+1]<=right){
      rnow++;
      right=max(right,x[rnow]+a[rnow]);
      left=min(left,x[rnow]-a[rnow]);
      f=true;
    }
    if(x[lnow-1]>=left){
      lnow--;
      right=max(right,x[lnow]+a[lnow]);
      left=min(left,x[lnow]-a[lnow]);
      f=true;
    }
  }
  cout<<rnow-lnow+1<<endl;
}
0