結果

問題 No.871 かえるのうた
コンテスト
ユーザー face4
提出日時 2019-06-11 22:19:55
言語 Java
(openjdk 27 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 269 ms / 2,000 ms
+ 339µs
コード長 1,313 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,708 ms
コンパイル使用メモリ 91,424 KB
実行使用メモリ 71,204 KB
最終ジャッジ日時 2026-10-19 13:50:09
合計ジャッジ時間 11,420 ms
ジャッジサーバーID
(参考情報)
judge6_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line[] = br.readLine().split(" ");
        int n = Integer.parseInt(line[0]), k = Integer.parseInt(line[1])-1;
        long x[] = new long[n];
        long a[] = new long[n];
        line = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            x[i] = Long.parseLong(line[i]);
        }
        line = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Long.parseLong(line[i]);
        }
        int l = k, r = k;
        long ld = x[k]-a[k], rd = x[k]+a[k];
        boolean update = true;
        while(update){
            update = false;
            while(l-1 >= 0 && ld <= x[l-1]){
                update = true;
                l--;
                ld = Math.min(ld, x[l]-a[l]);
                rd = Math.max(rd, x[l]+a[l]);
            }
            while(r+1 < n && x[r+1] <= rd){
                update = true;
                r++;
                rd = Math.max(rd, x[r]+a[r]);
                ld = Math.min(ld, x[r]-a[r]);
            }
        }
        System.out.println(r-l+1);
    }
}
0