結果

問題 No.2804 Fixer And Ratism
ユーザー naut3naut3
提出日時 2024-07-13 11:59:13
言語 Rust
(1.77.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,902 bytes
コンパイル時間 14,189 ms
コンパイル使用メモリ 402,332 KB
実行使用メモリ 8,848 KB
最終ジャッジ日時 2024-07-13 11:59:33
合計ジャッジ時間 17,145 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 19 ms
6,944 KB
testcase_04 AC 9 ms
6,944 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 15 ms
6,944 KB
testcase_07 AC 9 ms
6,944 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 35 ms
6,940 KB
testcase_12 AC 17 ms
6,940 KB
testcase_13 AC 7 ms
6,940 KB
testcase_14 AC 16 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 16 ms
6,944 KB
testcase_17 AC 11 ms
6,944 KB
testcase_18 AC 24 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 43 ms
6,940 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 53 ms
7,296 KB
testcase_24 AC 25 ms
7,168 KB
testcase_25 AC 55 ms
7,168 KB
testcase_26 AC 34 ms
7,296 KB
testcase_27 AC 24 ms
7,168 KB
testcase_28 AC 56 ms
7,168 KB
testcase_29 AC 33 ms
8,836 KB
testcase_30 AC 34 ms
8,848 KB
testcase_31 AC 24 ms
7,296 KB
testcase_32 AC 48 ms
8,408 KB
testcase_33 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        mut N: usize, Q: usize,
    }

    let mut s1 = vec![];
    let mut s2 = vec![];

    for _ in 0..Q {
        input! {
            t: u8,
        }

        if t == 1 {
            input! {
                s: String,
                r: u32,
            }

            s2.push((s, r));
        } else if t == 2 {
            input! {
                x: usize,
            }

            N -= x;
        } else {
            input! {
                s: String,
                x: usize,
            }

            N += x;

            for i in 0..s2.len() {
                if s2[i].0 == s {
                    let r = s2[i].1;
                    s1.push((s, r));
                    s2.remove(i);
                    break;
                }
            }
        }

        s1.sort_by_key(|(_, r)| *r);
        s2.sort_by_key(|(_, r)| *r);
        s1.reverse();
        s2.reverse();

        if s1.len() + s2.len() > N {
            let mut removed_names = vec![];

            let d = s1.len() + s2.len() - N;

            for _ in 0..d {
                if s2.len() > 0 {
                    let (name, r) = s2.pop().unwrap();
                    removed_names.push((name, r));
                } else {
                    let (name, r) = s1.pop().unwrap();
                    removed_names.push((name, r));
                }
            }

            removed_names.sort_by_key(|(_, r)| *r);
            println!(
                "{}",
                removed_names
                    .iter()
                    .map(|(name, _)| name)
                    .collect::<Vec<_>>()
                    .iter()
                    .map(|x| x.to_string())
                    .collect::<Vec<_>>()
                    .join("\n")
            );
        }
    }
}
0