結果
問題 | No.59 鉄道の旅 |
ユーザー |
![]() |
提出日時 | 2014-12-19 19:50:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 710 ms / 5,000 ms |
コード長 | 959 bytes |
コンパイル時間 | 2,190 ms |
コンパイル使用メモリ | 77,204 KB |
実行使用メモリ | 56,244 KB |
最終ジャッジ日時 | 2024-12-24 20:30:04 |
合計ジャッジ時間 | 8,005 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
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); } }