Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |