結果

問題 No.59 鉄道の旅
ユーザー kou6839kou6839
提出日時 2014-12-19 19:35:51
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 929 bytes
コンパイル時間 1,775 ms
コンパイル使用メモリ 73,764 KB
実行使用メモリ 66,888 KB
最終ジャッジ日時 2023-08-26 05:34:32
合計ジャッジ時間 4,975 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
58,316 KB
testcase_01 AC 112 ms
59,996 KB
testcase_02 AC 110 ms
60,044 KB
testcase_03 AC 122 ms
59,920 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
権限があれば一括ダウンロードができます

ソースコード

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<=1000001;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[100001];
    	int ans=0;
        for(int i=0;i<n;i++){
        	int temp = sc.nextInt();
        	if(temp>0){
        		if( (bit.sum(1000000)-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