結果
問題 |
No.59 鉄道の旅
|
ユーザー |
![]() |
提出日時 | 2014-12-19 19:37:15 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 928 bytes |
コンパイル時間 | 1,967 ms |
コンパイル使用メモリ | 76,816 KB |
実行使用メモリ | 52,476 KB |
最終ジャッジ日時 | 2024-12-24 20:29:00 |
合計ジャッジ時間 | 5,299 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | WA * 2 RE * 10 |
ソースコード
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[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); } }