use proconio::input; fn main() { input! { n:usize, x:usize, y:usize, pc:[(i64,char);n], } let mut abs = vec![(0, 0); x + y]; for i in 0..n { if pc[i].1 == 'A' { abs[i % (x + y)].0 += pc[i].0; } else { abs[i % (x + y)].1 += pc[i].0; } } abs.sort_by(|&x, &y| (y.0 - y.1).cmp(&(x.0 - x.1))); let mut ans = 0; for i in 0..x { ans += abs[i].0; } for i in 0..y { ans += abs[x + i].1; } println!("{}", ans); }