結果

問題 No.999 てん vs. ほむ
ユーザー cotton_fn_cotton_fn_
提出日時 2020-02-29 10:54:52
言語 Rust
(1.77.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 3,036 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 173,916 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-21 21:30:14
合計ジャッジ時間 2,670 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 14 ms
5,888 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 15 ms
6,400 KB
testcase_14 AC 15 ms
6,272 KB
testcase_15 AC 15 ms
6,272 KB
testcase_16 AC 15 ms
6,272 KB
testcase_17 AC 11 ms
5,376 KB
testcase_18 AC 11 ms
5,376 KB
testcase_19 AC 11 ms
5,376 KB
testcase_20 AC 11 ms
5,376 KB
testcase_21 AC 14 ms
6,272 KB
testcase_22 AC 14 ms
6,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused)]

use std::{
    io::{self, prelude::*},
    mem::{replace, swap},
    iter,
};

pub struct Input<R> {
    src: R,
    buf: Vec<u8>,
    pos: usize,
}
impl<R: BufRead> Input<R> {
    pub fn new(src: R) -> Self {
        Self {
            src,
            buf: Vec::new(),
            pos: 0,
        }
    }
    pub fn input_raw(&mut self) -> &[u8] {
        loop {
            self.advance_while(|b| b.is_ascii_whitespace());
            if self.pos == self.buf.len() {
                self.buf.clear();
                self.src.read_until(b'\n', &mut self.buf).expect("io error");
                self.pos = 0;
            } else {
                break;
            }
        }
        let start = self.pos;
        self.advance_while(|b| !b.is_ascii_whitespace());
        &self.buf[start..self.pos]
    }
    fn advance_while(&mut self, f: impl Fn(u8) -> bool) {
        while self.buf.get(self.pos).map_or(false, |b| f(*b)) {
            self.pos += 1;
        }
    }
    pub fn input<T: InputParse>(&mut self) -> T {
        T::input(self)
    }
}
pub trait InputParse {
    fn input<R: BufRead>(input: &mut Input<R>) -> Self;
}
macro_rules! input_from_str_impls {
    { $($T:ty)* } => {
        $(impl InputParse for $T {
            fn input<R: BufRead>(input: &mut Input<R>) -> Self {
                String::from_utf8_lossy(input.input_raw())
                    .parse()
                    .expect("parse error")
            }
        })*
    };
}
macro_rules! input_tuple_impls {
    { $(($($T:ident),+))* } => {
        $(impl<$($T: InputParse),+> InputParse for ($($T),+) {
            fn input<R: BufRead>(input: &mut Input<R>) -> Self {
                ($(input.input::<$T>()),+)
            }
        })*
    };
}
input_from_str_impls! {
    String char bool f32 f64
    isize i8 i16 i32 i64 i128
    usize u8 u16 u32 u64 u128
}
input_tuple_impls! {
    (A, B)
    (A, B, C)
    (A, B, C, D)
    (A, B, C, D, E)
    (A, B, C, D, E, F)
    (A, B, C, D, E, F, G)
}

macro_rules! output {
    ($out:expr, $($args:expr),*) => {
        $out.write_fmt(format_args!($($args),*))
    };
}
macro_rules! outputln {
    ($out:expr, $($args:expr),*) => {
        output!($out, $($args),*);
        outputln!($out);
    };
    ($out:expr) => {
        output!($out, "\n");
    };
}

fn main() {
    let stdin = io::stdin();
    let mut input = Input::new(stdin.lock());
    let stdout = io::stdout();
    let mut out = io::BufWriter::new(stdout.lock());

    let n = input.input();
    let mut a: Vec<i64> = iter::repeat_with(|| {
        let (x, y): (i64, i64) = input.input();
        x - y
    })
    .take(n)
    .collect();
    let mut lsum = vec![0];
    let mut rsum = vec![0];
    for x in &a {
        lsum.push(lsum.last().unwrap() + *x);
    }
    for x in a.iter().rev() {
        rsum.push(rsum.last().unwrap() - *x);
    }
    rsum.reverse();
    // dbg!(&a, &lsum, &rsum);
    let ans = lsum.iter().zip(rsum).fold(-(1 << 60), |cur, (x, y)| cur.max(x + y));
    outputln!(&mut out, "{}", ans);
}
0