Skip to content

Commit

Permalink
math-and-algorithm 081-083
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 12, 2022
1 parent cbeea40 commit 559f87d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
10 changes: 7 additions & 3 deletions math-and-algorithm/src/bin/081.rs
@@ -1,10 +1,14 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
let c1 = n / 10_000;
let n1 = n % 10_000;
let c2 = n1 / 5_000;
let n2 = n1 % 5_000;
let c3 = n2 / 1_000;
let ans = c1 + c2 + c3;
println!("{}", ans);
}
15 changes: 12 additions & 3 deletions math-and-algorithm/src/bin/082.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(|&(_, r)| r);
let mut count = 1;
let mut p = lr[0].1;
for (l, r) in lr.into_iter().skip(1) {
if l >= p {
count += 1;
p = r;
}
}
let ans = count;
println!("{}", ans);
}
14 changes: 11 additions & 3 deletions math-and-algorithm/src/bin/083.rs
@@ -1,10 +1,18 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
mut a: [i64; n],
mut b: [i64; n],
};
let ans = n - a.len();
a.sort();
b.sort();
let ans = a
.iter()
.copied()
.zip(b.iter().copied())
.map(|(a, b)| (a - b).abs())
.sum::<i64>();
println!("{}", ans);
}

0 comments on commit 559f87d

Please sign in to comment.