結果

問題 No.59 鉄道の旅
ユーザー kou6839
提出日時 2014-12-19 19:38:54
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 931 bytes
コンパイル時間 2,456 ms
コンパイル使用メモリ 77,472 KB
実行使用メモリ 62,004 KB
最終ジャッジ日時 2024-12-24 20:29:16
合計ジャッジ時間 8,991 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;
 
class BIT{
	int[] bit=new int[2000001];
    void add(int a,int w){;
    	for(int x = a;x<=2000000;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(2000000)-bit.sum(temp))>=k) continue;
        		bit.add(temp,1);
        		aru[temp]++;
        		ans++;
        	}else{
        		if(aru[-temp]>0) {
        			ans--;
        			bit.add(-temp,-1);
        		}
        	}
        }
        System.out.println(ans);
    }
}		
0