結果
| 問題 | No.1251 絶対に間違ってはいけない最小化問題 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-11-13 20:19:38 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 60 ms / 2,000 ms | 
| コード長 | 1,158 bytes | 
| コンパイル時間 | 13,920 ms | 
| コンパイル使用メモリ | 379,764 KB | 
| 実行使用メモリ | 12,416 KB | 
| 最終ジャッジ日時 | 2024-09-15 01:53:06 | 
| 合計ジャッジ時間 | 25,842 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 42 | 
コンパイルメッセージ
warning: unused variable: `nb` --> src/main.rs:21:18 | 21 | let (na, nb) = pairs[i]; | ^^ help: if this is intentional, prefix it with an underscore: `_nb` | = note: `#[warn(unused_variables)]` on by default
ソースコード
fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<isize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).ok();
    let b: Vec<isize> = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut pairs = (0..n).map(|i| (a[i], b[i])).collect::<Vec<_>>();
    pairs.sort();
    let mut bminus = pairs.iter().map(|&(_, b)| b).sum::<isize>();
    let mut bplus = 0isize;
    let mut summary = (0..n).map(|i| pairs[i].1 * (pairs[0].0 - pairs[i].0).abs()).sum::<isize>();
    let mut x = pairs[0].0;
    let mut minval = summary;
    for i in 1..n {
        let (na, nb) = pairs[i];
        let (pa, pb) = pairs[i-1];
        let diff = na - pa;
        bminus -= pb;
        bplus += pb;
        summary = summary - bminus * diff + bplus * diff;
        if summary < minval {
            x = na;
            minval = summary;
        }
    }
    println!("{} {}", x, minval);
}
            
            
            
        