結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー o2co2c
提出日時 2020-10-09 21:59:16
言語 Rust
(1.77.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,991 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 158,928 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2023-09-27 16:53:08
合計ジャッジ時間 13,439 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 0 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 61 ms
13,984 KB
testcase_19 AC 58 ms
13,744 KB
testcase_20 AC 34 ms
8,520 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 37 ms
8,808 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 49 ms
12,512 KB
testcase_25 AC 35 ms
8,612 KB
testcase_26 AC 13 ms
4,648 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 64 ms
14,592 KB
testcase_29 AC 67 ms
14,560 KB
testcase_30 AC 65 ms
14,592 KB
testcase_31 AC 66 ms
14,492 KB
testcase_32 AC 65 ms
14,524 KB
testcase_33 AC 65 ms
14,576 KB
testcase_34 AC 69 ms
14,572 KB
testcase_35 AC 64 ms
14,584 KB
testcase_36 AC 64 ms
14,564 KB
testcase_37 AC 65 ms
14,564 KB
testcase_38 AC 64 ms
14,592 KB
testcase_39 AC 65 ms
14,576 KB
testcase_40 AC 66 ms
14,572 KB
testcase_41 AC 66 ms
14,576 KB
testcase_42 AC 68 ms
14,576 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
use {std::cmp::*, std::collections::*, std::io::Write, std::ops::*};

#[allow(unused_macros)]
macro_rules !dbg {($($e :expr ) ,*) =>{#[cfg (debug_assertions ) ] $({let (e ,mut err ) =(stringify !($e ) ,std ::io ::stderr () ) ;writeln !(err ,"{} = {:?}" ,e ,$e ) .unwrap () } ) *} ;}
#[allow(unused_macros)]
macro_rules !min {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::min ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::min ($a ,min !($($rest ) ,+) ) } } ;}
#[allow(unused_macros)]
macro_rules !chmin {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_min =min !($($cmps ) ,+) ;if $base >cmp_min {$base =cmp_min ;true } else {false } } } ;}
#[allow(unused_macros)]
macro_rules !max {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::max ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::max ($a ,max !($($rest ) ,+) ) } } ;}
#[allow(unused_macros)]
macro_rules !chmax {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_max =max !($($cmps ) ,+) ;if $base <cmp_max {$base =cmp_max ;true } else {false } } } ;}

#[allow(dead_code)]
mod scanner {
    use std;
    use std::io::Read;
    use std::str::FromStr;
    use std::str::SplitWhitespace;
    pub struct Scanner<'a> {
        it: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a String) -> Scanner<'a> {
            Scanner {
                it: s.split_whitespace(),
            }
        }
        pub fn next<T: FromStr>(&mut self) -> T {
            match self.it.next().unwrap().parse::<T>() {
                Ok(v) => v,
                _ => panic!("Scanner error"),
            }
        }
        pub fn next_chars(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }
        pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
            (0..len).map(|_| self.next()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}

fn main() {
    let sc = scanner::read_string();
    let mut sc = scanner::Scanner::new(&sc);
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());

    let n: usize = sc.next();
    let mut a: Vec<i64> = sc.next_vec(n);
    let b: Vec<i64> = sc.next_vec(n);
    let mut ab = vec![];
    for i in 0..n {
        ab.push((a[i], b[i]));
    }
    ab.sort();
    let mut sum = 0;
    for i in 1..n {
        let (a, b) = ab[i];
        sum += (a - ab[0].0).abs() * b;
    }
    let mut bc = vec![0; n + 1];
    for i in 0..n {
        bc[i + 1] = bc[i] + ab[i].1;
    }

    a.sort();
    let mut ans = (sum, a[0]);
    for i in 1..n {
        sum += bc[i] * (a[i] - a[i - 1]);
        sum -= (bc[n] - bc[i]) * (a[i] - a[i - 1]);
        if ans.0 > sum {
            ans = (sum, a[i]);
        }
    }
    writeln!(out, "{} {}", ans.1, ans.0).unwrap();
}
0