結果
問題 |
No.871 かえるのうた
|
ユーザー |
|
提出日時 | 2019-08-30 19:17:14 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 392 ms / 2,000 ms |
コード長 | 1,647 bytes |
コンパイル時間 | 2,162 ms |
コンパイル使用メモリ | 76,372 KB |
実行使用メモリ | 67,144 KB |
最終ジャッジ日時 | 2024-11-30 10:44:25 |
合計ジャッジ時間 | 11,815 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
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 buf = br.readLine(); if(buf.charAt(0) == ' ' || buf.charAt(buf.length()-1) == ' ') System.exit(1); String line[] = buf.split(" "); int n = Integer.parseInt(line[0]), k = Integer.parseInt(line[1])-1; long x[] = new long[n]; long a[] = new long[n]; buf = br.readLine(); if(buf.charAt(0) == ' ' || buf.charAt(buf.length()-1) == ' ') System.exit(1); line = buf.split(" "); for(int i = 0; i < n; i++){ x[i] = Long.parseLong(line[i]); } buf = br.readLine(); if(buf.charAt(0) == ' ' || buf.charAt(buf.length()-1) == ' ') System.exit(1); line = buf.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); } }