Submission #2115634
Source Code Expand
/** * _ _ __ _ _ _ _ _ _ _ * | | | | / / | | (_) | (_) | | (_) | | * | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___ * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __| * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ V / __/ | | | |_| \__ \ |_ \__ \ | | | | |_) | |_) | __/ |_\__ \ * |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___| |_| \__,_|___/\__| |___/_| |_|_| .__/| .__/ \___|\__|___/ * | | | | | | * |_| |_| |_| * * https://github.com/hatoo/competitive-rust-snippets */ #[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::iter::FromIterator; #[allow(unused_imports)] use std::io::{stdin, stdout, BufWriter, Write}; mod util { use std::io::{stdin, stdout, BufWriter, StdoutLock}; use std::str::FromStr; use std::fmt::Debug; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn gets<T: FromStr>() -> Vec<T> where <T as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) { let out = stdout(); let writer = BufWriter::new(out.lock()); f(writer) } } #[allow(unused_macros)] macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } #[derive(Eq, PartialEq, Clone, Debug)] /// Equivalent to std::cmp::Reverse pub struct Rev<T>(pub T); impl<T: PartialOrd> PartialOrd for Rev<T> { fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> { other.0.partial_cmp(&self.0) } } impl<T: Ord> Ord for Rev<T> { fn cmp(&self, other: &Rev<T>) -> Ordering { other.0.cmp(&self.0) } } #[allow(dead_code)] fn main() { let n = get!(usize); let aa = util::gets::<i64>(); let mut h: BinaryHeap<Rev<i64>> = aa[..n].iter().map(|&a| Rev(a)).collect(); let mut sum = aa[..n].iter().sum::<i64>(); let mut front = vec![sum]; for &a in &aa[n..2 * n] { sum += a; h.push(Rev(a)); sum -= h.pop().unwrap().0; front.push(sum); } let mut h: BinaryHeap<i64> = aa[2 * n..].iter().cloned().collect(); let mut sum = aa[2 * n..].iter().sum::<i64>(); let mut back = vec![sum]; for &a in aa[n..2 * n].iter().rev() { sum += a; h.push(a); sum -= h.pop().unwrap(); back.push(sum); } println!( "{}", front .iter() .zip(back.iter().rev()) .map(|(&x, &y)| x - y) .max() .unwrap() ); }
Submission Info
Submission Time | |
---|---|
Task | D - 3N Numbers |
User | hatoo |
Language | Rust (1.15.1) |
Score | 500 |
Code Size | 4835 Byte |
Status | AC |
Exec Time | 55 ms |
Memory | 16368 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 200 / 200 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
Subtask | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 2 ms | 4352 KB |
0_01.txt | AC | 2 ms | 4352 KB |
0_02.txt | AC | 2 ms | 4352 KB |
1_00.txt | AC | 2 ms | 4352 KB |
1_01.txt | AC | 2 ms | 4352 KB |
1_02.txt | AC | 2 ms | 4352 KB |
1_03.txt | AC | 2 ms | 4352 KB |
1_04.txt | AC | 2 ms | 4352 KB |
1_05.txt | AC | 2 ms | 4352 KB |
1_06.txt | AC | 2 ms | 4352 KB |
1_07.txt | AC | 2 ms | 4352 KB |
1_08.txt | AC | 2 ms | 4352 KB |
1_09.txt | AC | 2 ms | 4352 KB |
1_10.txt | AC | 2 ms | 4352 KB |
1_11.txt | AC | 2 ms | 4352 KB |
1_12.txt | AC | 2 ms | 4352 KB |
1_13.txt | AC | 2 ms | 4352 KB |
1_14.txt | AC | 2 ms | 4352 KB |
1_15.txt | AC | 2 ms | 4352 KB |
1_16.txt | AC | 2 ms | 4352 KB |
1_17.txt | AC | 2 ms | 4352 KB |
1_18.txt | AC | 2 ms | 4352 KB |
1_19.txt | AC | 2 ms | 4352 KB |
1_20.txt | AC | 2 ms | 4352 KB |
1_21.txt | AC | 2 ms | 4352 KB |
1_22.txt | AC | 2 ms | 4352 KB |
1_23.txt | AC | 2 ms | 4352 KB |
2_00.txt | AC | 29 ms | 16368 KB |
2_01.txt | AC | 47 ms | 14324 KB |
2_02.txt | AC | 38 ms | 14324 KB |
2_03.txt | AC | 42 ms | 14324 KB |
2_04.txt | AC | 42 ms | 14324 KB |
2_05.txt | AC | 41 ms | 14324 KB |
2_06.txt | AC | 43 ms | 14324 KB |
2_07.txt | AC | 45 ms | 14324 KB |
2_08.txt | AC | 31 ms | 16368 KB |
2_09.txt | AC | 30 ms | 15336 KB |
2_10.txt | AC | 31 ms | 16368 KB |
2_11.txt | AC | 30 ms | 15336 KB |
2_12.txt | AC | 55 ms | 14324 KB |
2_13.txt | AC | 54 ms | 14324 KB |
2_14.txt | AC | 54 ms | 14324 KB |
2_15.txt | AC | 54 ms | 14324 KB |