結果

問題 No.59 鉄道の旅
ユーザー kohaku_kohaku
提出日時 2017-01-21 20:57:33
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 741 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 75,020 KB
実行使用メモリ 109,244 KB
最終ジャッジ日時 2024-12-25 15:30:35
合計ジャッジ時間 31,948 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int [] c = new int [1000001];
        for(int i=0; i<N; i++){
            int W = sc.nextInt();
            if(W>0){
                int tmp=0;
                for(int j=W; j<1000001; j++){
                    tmp+=c[j];
                }
                if(tmp<K){
                    c[W]++;
                }
            }else{
                W*=-1;
                if(c[W]>0)c[W]--;
            }
        }
        int ans=0;
        for(int j=0; j<1000001; j++){
            ans+=c[j];
        }
        System.out.println(ans);
    }
}
0