Skip to content

Commit

Permalink
arc134 b
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed May 25, 2022
1 parent 1dca6cd commit aee0ac9
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions arc134/src/bin/b.rs
@@ -1,10 +1,33 @@
use proconio::{input, marker::Usize1};
use std::{cmp::Reverse, collections::BinaryHeap};

use proconio::{input, marker::Chars};

fn main() {
input! {
n: usize,
a: [Usize1; n],
s: Chars,
};
let ans = n - a.len();
println!("{}", ans);

let mut pq = BinaryHeap::new();
for (i, s_i) in s.iter().copied().enumerate() {
pq.push((Reverse(s_i), i));
}

let mut r = n;
let mut ans = s.clone();
for (l, s_l) in s.iter().copied().enumerate() {
while let Some((Reverse(s_j), j)) = pq.pop() {
if j < l || r <= j {
continue;
}
if s_j < s_l {
r = j;
ans.swap(l, r);
} else {
pq.push((Reverse(s_j), j));
}
break;
}
}
println!("{}", ans.iter().collect::<String>());
}

0 comments on commit aee0ac9

Please sign in to comment.