Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::io;
- use std::str::FromStr;
- use std::fmt::Debug;
- struct Scanner {
- buf: Vec<String>
- }
- impl Scanner {
- pub fn new() -> Self {
- Self {
- buf: vec![]
- }
- }
- pub fn next<T>(&mut self) -> T
- where
- T: FromStr,
- <T as FromStr>::Err: Debug,
- {
- if !self.buf.is_empty() {
- return self.buf.pop().unwrap().parse::<T>().unwrap();
- }
- let mut line = String::new();
- io::stdin().read_line(&mut line).unwrap();
- self.buf.extend(line
- .trim()
- .split_ascii_whitespace()
- .map(|i| i.to_string())
- .collect::<Vec<String>>());
- return self.buf.pop().unwrap().parse::<T>().unwrap()
- }
- }
- fn main() {
- let mut scanner = Scanner::new();
- let testcase: usize = scanner.next();
- for _ in 0..testcase {
- let mut array: Vec<i32> = Vec::new();
- let array_size: usize = scanner.next();
- for _ in 0..array_size {
- array.push(scanner.next());
- }
- if array_size <= 1 {
- println!("{}", array[0]);
- continue;
- }
- array.sort();
- let mut max_difference = 0;
- let mut idx = 0;
- while idx+1 < array_size {
- let diff = (array[idx] - array[idx+1]).abs();
- if diff > max_difference {
- max_difference = diff;
- }
- idx += 1;
- }
- println!("{}", std::cmp::max(max_difference, array[0]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement