結果
| 問題 | No.59 鉄道の旅 | 
| コンテスト | |
| ユーザー |  koyopro | 
| 提出日時 | 2015-09-30 15:23:27 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 987 bytes | 
| コンパイル時間 | 1,223 ms | 
| コンパイル使用メモリ | 157,828 KB | 
| 実行使用メモリ | 7,424 KB | 
| 最終ジャッジ日時 | 2024-12-24 21:55:41 | 
| 合計ジャッジ時間 | 2,912 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 8 RE * 4 | 
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
int N,K,W;
#define MAX1 (int)1e6+100
#define MAX2 (int)1e6/500+100
int count1[MAX1];
int count2[MAX2];
int jforn(int n) {
    return n / 500;
}
int count(int n) {
    int j = jforn(n);
    int ret = 0;
    RREP(i,MAX2) {
        if (i <= j) break;
        ret += count2[i];
    }
    RREP(i,500) {
        int k = j * 500 + i;
        if (k < n) break;
        ret += count1[k];
    }
    return ret;
}
signed main()
{
    cin>>N>>K;
    REP(i,N) {
        cin >> W;
        int j = abs(W);
        if (W > 0) {
            if (count(j) < K) {
                count1[j]++;
                count2[jforn(j)]++;
            }
        } else {
            // あれば下ろせる
            if (count1[j]) {
                count1[j]--;
                count2[jforn(j)]--;
            }
        }
    }
    cout << count(0) << endl;
    return 0;
}
            
            
            
        