結果
問題 | No.999 てん vs. ほむ |
ユーザー |
![]() |
提出日時 | 2020-04-19 17:16:07 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 1,275 bytes |
コンパイル時間 | 16,972 ms |
コンパイル使用メモリ | 385,732 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-05 19:14:00 |
合計ジャッジ時間 | 19,043 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#![allow(unused_imports)] #![allow(non_snake_case)] use std::collections::HashMap; use std::collections::HashSet; use std::collections::VecDeque; #[allow(unused_macros)] macro_rules! read { ([$t:ty] ; $n:expr) => ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>()); ($($t:ty),+ ; $n:expr) => ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>()); ([$t:ty]) => (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>()); ($t:ty) => (rl().parse::<$t>().unwrap()); ($($t:ty),*) => {{ let buf = rl(); let mut w = buf.split_whitespace(); ($(w.next().unwrap().parse::<$t>().unwrap()),*) }}; } #[allow(dead_code)] fn rl() -> String { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().to_owned() } fn main() { let n = read!(usize); let v = read!([isize]); let mut table_l = vec![0isize; n+1]; let mut table_r = vec![0isize; n+1]; for i in 0..n { table_l[i+1] = table_l[i] + v[i*2] - v[i*2+1]; table_r[(n-1)-i] = table_r[(n-1)-i+1] + v[2*n-1-(i*2)] - v[2*n-1-(i*2+1)]; } let max = table_l.iter().zip(table_r.iter()).max_by_key(|e| e.0 + e.1).unwrap(); println!("{}", max.0 + max.1); }