Created
October 20, 2017 12:13
-
-
Save Odomontois/0016cde9386502c0c7ce15b22c891cfc to your computer and use it in GitHub Desktop.
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
use std::io::stdin; | |
use std::io::prelude::*; | |
use std::iter::*; | |
use std::str::SplitWhitespace; | |
fn main() { | |
let mut inp = InRead::new(); | |
let t = inp.int(); | |
for _ in 0..t { | |
let n = inp.int(); | |
let xs = inp.int_vec(); | |
let &xm = xs.iter().min().unwrap(); | |
let ans: i64 = (xm - 3..xm + 1) | |
.map(|r| xs.iter() | |
.map(|&x| | |
((x - r) / 5 + (((x - r) % 5) >> 1) + (((x - r) % 5) & 1)) as i64 | |
).sum()).min().unwrap(); | |
println!("{}", ans); | |
} | |
} | |
struct InRead(String); | |
impl InRead { | |
fn new() -> InRead { | |
InRead(String::new()) | |
} | |
fn get_line(self: &mut Self) { | |
self.0.clear(); | |
stdin().read_line(&mut self.0); | |
} | |
fn parse_int(s: &str) -> i32 { s.parse().unwrap() } | |
fn ints(self: &mut Self) -> Map<SplitWhitespace, fn(&str) -> i32> { | |
self.get_line(); | |
self.0.split_whitespace().map(InRead::parse_int) | |
} | |
fn int_vec(self: &mut Self) -> Vec<i32> { self.ints().collect() } | |
fn int(self: &mut Self) -> i32 { self.ints().next().unwrap() } | |
fn int2(self: &mut Self) -> (i32, i32) { | |
let mut is = self.ints(); | |
(is.next().unwrap(), is.next().unwrap()) | |
} | |
fn int3(self: &mut Self) -> (i32, i32, i32) { | |
let mut is = self.ints(); | |
(is.next().unwrap(), is.next().unwrap(), is.next().unwrap()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment