結果

問題 No.1430 Coup de Coupon
ユーザー StrorkisStrorkis
提出日時 2021-03-14 16:35:09
言語 Rust
(1.77.0)
結果
AC  
実行時間 709 ms / 2,000 ms
コード長 1,847 bytes
コンパイル時間 5,605 ms
コンパイル使用メモリ 177,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 23:54:51
合計ジャッジ時間 9,817 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 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 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 251 ms
5,376 KB
testcase_10 AC 433 ms
5,376 KB
testcase_11 AC 569 ms
5,376 KB
testcase_12 AC 667 ms
5,376 KB
testcase_13 AC 709 ms
5,376 KB
testcase_14 AC 684 ms
5,376 KB
testcase_15 AC 584 ms
5,376 KB
testcase_16 AC 474 ms
5,376 KB
testcase_17 AC 248 ms
5,376 KB
testcase_18 AC 708 ms
5,376 KB
testcase_19 AC 705 ms
5,376 KB
testcase_20 AC 365 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 14 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::BTreeMap;

fn main() {
    let ref mut buf = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), buf).ok();
    let mut iter = buf.split_whitespace();

    macro_rules! scan {
        ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::<Vec<_>>());
        (($($t:tt),*)) => (($(scan!($t)),*));
        (Usize1) => (scan!(usize) - 1);
        (Bytes) => (scan!(String).into_bytes());
        ($t:ty) => (iter.next().unwrap().parse::<$t>().unwrap());
    }

    let (n, c) = scan!((usize, usize));

    let mut items = scan!([i32; n]);
    items.sort_by(|a, b| b.cmp(a));

    let mut coupons = vec![vec![]; 2];
    for _ in 0..c {
        let (t, x) = scan!((Usize1, i32));
        coupons[t].push(x);
    }
    for coupon in coupons.iter_mut() {
        (*coupon).sort_by(|a, b| b.cmp(a));
    }
    let len1 = coupons[0].len();
    let len2 = coupons[1].len();

    let mut map = BTreeMap::new();
    map.insert((0, 0), 0);

    let mut sum = 0;
    for i in 0..n {
        let p = items[i];
        if i >= c {
            sum += p;
            continue;
        }

        for c1 in (0..=i.min(len1)).rev() {
            let c2 = i - c1;
            if c2 > len2 {
                break;
            }

            let now = map.remove(&(c1, c2)).unwrap();
            if c1 < len1 {
                let next = now + (p - coupons[0][c1]).max(0);
                let value = map.entry((c1 + 1, c2)).or_insert(1 << 30);
                *value = (*value).min(next);
            }
            if c2 < len2 {
                let next = now + p / 100 * (100 - coupons[1][c2]);
                let value = map.entry((c1, c2 + 1)).or_insert(1 << 30);
                *value = (*value).min(next);
            }
        }
    }

    let ans = map.values().min().unwrap() + sum;
    println!("{}", ans);
}
0