結果
問題 | No.59 鉄道の旅 |
ユーザー | SSRS |
提出日時 | 2021-12-17 12:04:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 58 ms / 5,000 ms |
コード長 | 726 bytes |
コンパイル時間 | 1,691 ms |
コンパイル使用メモリ | 169,120 KB |
実行使用メモリ | 8,044 KB |
最終ジャッジ日時 | 2023-10-12 14:02:12 |
合計ジャッジ時間 | 3,337 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 1 ms
4,352 KB |
testcase_02 | AC | 1 ms
4,352 KB |
testcase_03 | AC | 1 ms
4,352 KB |
testcase_04 | AC | 51 ms
5,404 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 1 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,352 KB |
testcase_08 | AC | 7 ms
4,348 KB |
testcase_09 | AC | 6 ms
4,352 KB |
testcase_10 | AC | 6 ms
4,348 KB |
testcase_11 | AC | 3 ms
4,352 KB |
testcase_12 | AC | 15 ms
4,352 KB |
testcase_13 | AC | 47 ms
5,744 KB |
testcase_14 | AC | 58 ms
8,044 KB |
testcase_15 | AC | 2 ms
4,352 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N, K; cin >> N >> K; multiset<int> st1, st2; for (int i = 0; i < N; i++){ int W; cin >> W; if (W > 0){ if (st1.size() < K){ st1.insert(W); } else if (*st1.begin() < W){ st1.insert(W); st2.insert(*st1.begin()); st1.erase(st1.begin()); } } if (W < 0){ W = -W; if (st1.find(W) != st1.end()){ st1.erase(st1.find(W)); if (!st2.empty()){ st1.insert(*prev(st2.end())); st2.erase(prev(st2.end())); } } else if (st2.find(W) != st2.end()){ st2.erase(st2.find(W)); } } } cout << st1.size() + st2.size() << endl; }