結果

問題 No.871 かえるのうた
ユーザー k_6101k_6101
提出日時 2019-12-07 17:57:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,975 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 96,020 KB
実行使用メモリ 82,248 KB
最終ジャッジ日時 2023-08-26 22:11:06
合計ジャッジ時間 25,114 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,620 KB
testcase_01 AC 116 ms
55,636 KB
testcase_02 AC 115 ms
55,796 KB
testcase_03 AC 123 ms
55,840 KB
testcase_04 WA -
testcase_05 AC 120 ms
55,804 KB
testcase_06 AC 118 ms
55,828 KB
testcase_07 AC 124 ms
56,108 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 183 ms
58,912 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1,027 ms
75,052 KB
testcase_15 WA -
testcase_16 AC 915 ms
73,796 KB
testcase_17 AC 899 ms
74,236 KB
testcase_18 AC 440 ms
61,028 KB
testcase_19 WA -
testcase_20 AC 279 ms
61,448 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 124 ms
55,872 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 120 ms
55,744 KB
testcase_29 AC 603 ms
63,868 KB
testcase_30 WA -
testcase_31 AC 200 ms
60,520 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 447 ms
65,912 KB
testcase_35 WA -
testcase_36 AC 795 ms
72,140 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 621 ms
67,024 KB
testcase_41 AC 114 ms
56,136 KB
testcase_42 AC 489 ms
68,172 KB
testcase_43 AC 115 ms
55,652 KB
testcase_44 AC 122 ms
55,916 KB
testcase_45 AC 184 ms
59,028 KB
testcase_46 AC 118 ms
55,896 KB
testcase_47 AC 119 ms
55,708 KB
testcase_48 AC 123 ms
55,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    TreeMap<Long, Long> map = new TreeMap<>();
    public void solve() {
    	int N = Integer.parseInt(sc.next());
    	int K = Integer.parseInt(sc.next()) - 1;
    	long[] X = new long[N];
    	long[] A = new long[N];
    	for (int i = 0; i < N; i++) {
			X[i] = Long.parseLong(sc.next());
		}
    	for (int i = 0; i < N; i++) {
			A[i] = Long.parseLong(sc.next());
		}
    	for (int i = 0; i < N; i++) {
    		map.put(X[i], A[i]);
    	}
    	long min = X[K], svMin = min;
    	long max = X[K], svMax = max;
    	long lkey = X[K] - A[K] - 1;
    	long rkey = X[K] + A[K] + 1;
    	Entry<Long, Long> low;
    	Entry<Long, Long> high;
    	while(true) {
//    		out.println("min = " + min + "  lkey = " + lkey + "  max = " + max + "  rkey = " + rkey);
    		low = map.higherEntry(lkey);
    		high = map.lowerEntry(rkey);
    		if(low != null) {
//        		out.println(" low : X = " + low.getKey() + "  A = " + low.getValue());
        		min = Math.min(min, low.getKey());
        		lkey = Math.min(lkey, low.getKey() - low.getValue() - 1);
        		max = Math.max(max, low.getKey());
        		rkey = Math.max(rkey, low.getKey() + low.getValue() + 1);
    		}
    		if(high != null) {
//        		out.println(" high : X = " + high.getKey() + "  A = " + high.getValue());
        		min = Math.min(min, high.getKey());
        		lkey = Math.min(lkey, high.getKey() - high.getValue() - 1);
        		max = Math.max(max, high.getKey());
        		rkey = Math.max(rkey, high.getKey() + high.getValue() + 1);
    		}
    		if(min == svMin && max == svMax)	break;
    		svMin = min;	svMax = max;
    	}
    	int ans = 0;
    	for (int i = 0; i < N; i++) {
			if(X[i] >= min && X[i] <= max)	ans++;
		}
    	out.println(ans);
    }
    
    class PP{
    	public int key, val;
    	public PP(int key, int val) {
    		this.key = key;
    		this.val = val;
    	}
		public int getKey() {
			return key;
		}
		public void setKey(int key) {
			this.key = key;
		}
		public int getVal() {
			return val;
		}
		public void setVal(int val) {
			this.val = val;
		}
    }
}
0