From 559f87dcd10d20f9cda61e83646e9b9dcb52de11 Mon Sep 17 00:00:00 2001 From: bouzuya Date: Sat, 12 Mar 2022 11:49:19 +0900 Subject: [PATCH] math-and-algorithm 081-083 --- math-and-algorithm/src/bin/081.rs | 10 +++++++--- math-and-algorithm/src/bin/082.rs | 15 ++++++++++++--- math-and-algorithm/src/bin/083.rs | 14 +++++++++++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/math-and-algorithm/src/bin/081.rs b/math-and-algorithm/src/bin/081.rs index 2a9506c8..f0849fc7 100644 --- a/math-and-algorithm/src/bin/081.rs +++ b/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); } diff --git a/math-and-algorithm/src/bin/082.rs b/math-and-algorithm/src/bin/082.rs index 2a9506c8..c96b5fee 100644 --- a/math-and-algorithm/src/bin/082.rs +++ b/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); } diff --git a/math-and-algorithm/src/bin/083.rs b/math-and-algorithm/src/bin/083.rs index 2a9506c8..5e54e607 100644 --- a/math-and-algorithm/src/bin/083.rs +++ b/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::(); println!("{}", ans); }