Skip to content

Commit

Permalink
tessoku-book a39, b39
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Oct 27, 2022
1 parent 19ab102 commit d575382
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
15 changes: 12 additions & 3 deletions tessoku-book/src/bin/a39.rs
@@ -1,10 +1,19 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
mut lr: [(usize, usize); n],
};
let ans = n - a.len();
lr.sort_by_key(|&(l, r)| (r, l));
let mut count = 1_usize;
let mut prev = lr[0];
for (l, r) in lr.into_iter().skip(1) {
if prev.1 <= l {
count += 1;
prev = (l, r);
}
}
let ans = count;
println!("{}", ans);
}
22 changes: 19 additions & 3 deletions tessoku-book/src/bin/b39.rs
@@ -1,10 +1,26 @@
use proconio::{input, marker::Usize1};
use std::collections::BinaryHeap;

use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
d: usize,
mut xy: [(usize, usize); n],
};
let ans = n - a.len();
xy.sort_by_key(|&(x_i, _)| x_i);
let mut pq = BinaryHeap::new();
let mut sum = 0_usize;
let mut index = 0;
for d_i in 1..=d {
while index < n && xy[index].0 <= d_i {
pq.push(xy[index].1);
index += 1;
}
if let Some(x) = pq.pop() {
sum += x;
}
}
let ans = sum;
println!("{}", ans);
}

0 comments on commit d575382

Please sign in to comment.