Skip to content

Commit

Permalink
past202004-open f
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jan 1, 2024
1 parent cb77e93 commit 4a985d4
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions cargo-atcoder-1.70.0/contests/past202004-open/src/bin/f.rs
@@ -1,10 +1,30 @@
use std::collections::BTreeMap;

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

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

ab.sort();
let mut index = 0_usize;
let mut map = BTreeMap::new();
let mut sum = 0_usize;
for k in 0..n {
while index < ab.len() && ab[index].0 <= k {
*map.entry(ab[index].1).or_insert(0) += 1;
index += 1;
}

let max = *map.keys().next_back().unwrap();
let count = map.get_mut(&max).unwrap();
*count -= 1;
if *count == 0 {
map.remove(&max);
}
sum += max;
println!("{}", sum);
}
}

0 comments on commit 4a985d4

Please sign in to comment.