提出 #58970061


ソースコード 拡げる

use std::collections::{BTreeMap, BinaryHeap};
use itertools::Itertools;
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! { t : usize }
    for _ in 0..t { solve(); }
}

fn solve() {
    input! {
        n : usize,
        k : usize,
        a : [usize; n],
        b : [usize; n]
    }
    
    let mut mp = BTreeMap::new();
    for i in 0..n {
        mp.entry(a[i]).or_insert(vec![]).push(b[i]);
    }
    
    let mut ans = usize::MAX;
    let mut amax = 0;
    
    let mut pq1 = BinaryHeap::new();
    let mut sum = 0;
    
    for (key, v) in mp {
        amax = amax.max(key);
        for v in v {
            if pq1.len() < k { sum += v; pq1.push(v); }
            else {
                if *pq1.peek().unwrap() > v {
                    sum -= pq1.pop().unwrap();
                    sum += v;
                    pq1.push(v);
                }
            }
        }
        if pq1.len()>=k { ans = ans.min(amax * sum); }
    }
    
    println!("{}", ans);
}

提出情報

提出日時
問題 E - Max × Sum
ユーザ zeronosu77108
言語 Rust (rustc 1.70.0)
得点 475
コード長 1043 Byte
結果 AC
実行時間 210 ms
メモリ 27248 KiB

コンパイルエラー

warning: unused import: `itertools::Itertools`
 --> src/main.rs:2:5
  |
2 | use itertools::Itertools;
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `proconio::marker::Usize1`
 --> src/main.rs:4:5
  |
4 | use proconio::marker::Usize1;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 1
AC × 38
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_n_small_00.txt, 01_n_small_01.txt, 01_n_small_02.txt, 01_n_small_03.txt, 01_n_small_04.txt, 01_n_small_05.txt, 01_n_small_06.txt, 01_n_small_07.txt, 01_n_small_08.txt, 01_n_small_09.txt, 01_n_small_10.txt, 01_n_small_11.txt, 01_n_small_12.txt, 01_n_small_13.txt, 01_n_small_14.txt, 01_n_small_15.txt, 01_n_small_16.txt, 01_n_small_17.txt, 01_n_small_18.txt, 01_n_small_19.txt, 01_n_small_20.txt, 01_n_small_21.txt, 01_n_small_22.txt, 01_n_small_23.txt, 02_random_1_00.txt, 02_random_1_01.txt, 02_random_1_02.txt, 02_random_1_03.txt, 02_random_1_04.txt, 02_random_1_05.txt, 03_random_2_00.txt, 03_random_2_01.txt, 03_random_2_02.txt, 03_random_2_03.txt, 03_random_2_04.txt, 03_random_2_05.txt, 04_max_00.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 2052 KiB
01_n_small_00.txt AC 210 ms 4468 KiB
01_n_small_01.txt AC 210 ms 4356 KiB
01_n_small_02.txt AC 210 ms 4588 KiB
01_n_small_03.txt AC 115 ms 4076 KiB
01_n_small_04.txt AC 115 ms 4196 KiB
01_n_small_05.txt AC 114 ms 3912 KiB
01_n_small_06.txt AC 83 ms 3928 KiB
01_n_small_07.txt AC 83 ms 4044 KiB
01_n_small_08.txt AC 83 ms 3896 KiB
01_n_small_09.txt AC 66 ms 3772 KiB
01_n_small_10.txt AC 66 ms 3848 KiB
01_n_small_11.txt AC 67 ms 3804 KiB
01_n_small_12.txt AC 59 ms 3800 KiB
01_n_small_13.txt AC 58 ms 3816 KiB
01_n_small_14.txt AC 59 ms 3800 KiB
01_n_small_15.txt AC 41 ms 3832 KiB
01_n_small_16.txt AC 41 ms 3556 KiB
01_n_small_17.txt AC 41 ms 3728 KiB
01_n_small_18.txt AC 37 ms 3864 KiB
01_n_small_19.txt AC 37 ms 3700 KiB
01_n_small_20.txt AC 37 ms 3636 KiB
01_n_small_21.txt AC 34 ms 3624 KiB
01_n_small_22.txt AC 34 ms 3556 KiB
01_n_small_23.txt AC 34 ms 3700 KiB
02_random_1_00.txt AC 35 ms 15988 KiB
02_random_1_01.txt AC 70 ms 27248 KiB
02_random_1_02.txt AC 81 ms 25552 KiB
02_random_1_03.txt AC 64 ms 25424 KiB
02_random_1_04.txt AC 66 ms 25584 KiB
02_random_1_05.txt AC 70 ms 27044 KiB
03_random_2_00.txt AC 21 ms 10188 KiB
03_random_2_01.txt AC 24 ms 11700 KiB
03_random_2_02.txt AC 27 ms 10864 KiB
03_random_2_03.txt AC 21 ms 10132 KiB
03_random_2_04.txt AC 24 ms 11604 KiB
03_random_2_05.txt AC 28 ms 11100 KiB
04_max_00.txt AC 13 ms 11348 KiB