結果

問題 No.59 鉄道の旅
ユーザー kou6839kou6839
提出日時 2014-12-19 19:50:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 543 ms / 5,000 ms
コード長 959 bytes
コンパイル時間 1,785 ms
コンパイル使用メモリ 73,632 KB
実行使用メモリ 67,492 KB
最終ジャッジ日時 2023-08-26 05:35:25
合計ジャッジ時間 6,559 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
62,044 KB
testcase_01 AC 115 ms
62,260 KB
testcase_02 AC 114 ms
60,472 KB
testcase_03 AC 124 ms
62,396 KB
testcase_04 AC 488 ms
66,668 KB
testcase_05 AC 120 ms
62,244 KB
testcase_06 AC 130 ms
60,888 KB
testcase_07 AC 122 ms
62,076 KB
testcase_08 AC 237 ms
66,252 KB
testcase_09 AC 237 ms
66,088 KB
testcase_10 AC 249 ms
66,380 KB
testcase_11 AC 211 ms
66,548 KB
testcase_12 AC 435 ms
66,960 KB
testcase_13 AC 543 ms
67,492 KB
testcase_14 AC 502 ms
66,888 KB
testcase_15 AC 111 ms
62,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;
 
class BIT{
	int[] bit=new int[1000001];
    void add(int a,int w){;
    	for(int x = a;x<=1000000;x+=(x&-x)) {
    		bit[x] += w;
    	}
    }
    int sum(int a){
    	int ret = 0;
    	for(int x = a;x>0;x -= x& -x) ret += bit[x];
    	return ret;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt();
        int k = sc.nextInt();
        BIT bit = new BIT();
        int[] aru = new int[1000001];
    	int ans=0;
        for(int i=0;i<n;i++){
        	int temp = sc.nextInt();
        	if(temp>0){
        		if( (bit.sum(1000000)-bit.sum(temp-1))<k){
        		bit.add(temp,1);
        		aru[temp]++;
        		ans++;
        		}
        	}else{
        		if(aru[-temp]>0) {
        			ans--;
        			aru[-temp]--;
        			bit.add(-temp,-1);
        		}
        	}
        }
        System.out.println(ans);
    }
}	
0