結果

問題 No.59 鉄道の旅
ユーザー なおなお
提出日時 2014-11-06 23:57:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 922 ms / 5,000 ms
コード長 726 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 147,700 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 05:27:06
合計ジャッジ時間 3,649 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 292 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 44 ms
4,380 KB
testcase_09 AC 25 ms
4,376 KB
testcase_10 AC 34 ms
4,380 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 18 ms
4,380 KB
testcase_13 AC 381 ms
4,376 KB
testcase_14 AC 922 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> v;
    REP(i,N){
        int W; cin >> W;
        if(W<0){
            auto it = lower_bound(v.begin(), v.end(), -W);
            if(it == v.end()) continue;
            if(*it == -W){
                v.erase(it);
            }
        } else {
            auto it = lower_bound(v.begin(), v.end(), W);
            int n = it-v.begin();
            if(v.size()-n < K){
                cerr << W << ":" << v.size()-n << endl;
                v.insert(it, W);
            }
        }
    }
    cout << v.size() << endl;
    return 0;
}
0