Submission #68200041


Source Code Expand

#![allow(unused)]

use proconio::input;
use std::cmp::Reverse;
use std::collections::BTreeSet;

fn main() {
    input! {
        n: usize,
        m: usize,
        arr_p: [i64; n],
        arr_l: [i64; m],
        arr_d: [i64; m],
    }

    //                  Price
    //                  1 3 4
    // discount 0 (2):      o
    // discount 1 (3):      o
    // discount 2 (1):    o o

    let mut items = vec![];
    for i in 0..m {
        items.push((arr_l[i], arr_d[i]));
    }
    let total_discount = greedy_packing_01(items, arr_p.clone());
    let ans = arr_p.iter().sum::<i64>() - total_discount;
    println!("{ans}");
}

//             Sorted Boxes
//               A B C D
// item 0 (v0):  1
// item 1 (v1):  1 1 1
// item 2 (v2):  1 1 1 1
// item 3 (v3):  1 1
// Each row (item) is a 1...0 distribution.
fn greedy_packing_10(mut items: Vec<(i64, i64)>, bounds: Vec<i64>) -> i64 {
    let mut boxes = std::collections::BTreeSet::new();
    for (i, &b) in bounds.iter().enumerate() {
        boxes.insert((b, i));
    }
    items.sort_by_key(|&(w, v)| (std::cmp::Reverse(v), w));
    let mut ans = 0;
    for &(w, v) in &items {
        if let Some(&(b, i)) = boxes.range(..=(w, !0)).last() {
            boxes.remove(&(b, i));
            ans += v;
        }
    }
    ans
}

//             Sorted Boxes
//               A B C D
// item 0 (v0):      1 1
// item 1 (v1):    1 1 1
// item 2 (v2):        1
// item 3 (v3):  1 1 1 1
// Each row (item) is a 0...1 distribution.
fn greedy_packing_01(mut items: Vec<(i64, i64)>, boxes: Vec<i64>) -> i64 {
    let mut boxes = BTreeSet::from_iter((0..boxes.len()).map(|i| (boxes[i], i)));
    items.sort_by_key(|&(w, v)| (Reverse(v), w));
    let mut ans = 0;
    for &(w, v) in &items {
        if let Some(&(b, i)) = boxes.range((w, 0)..).next() {
            boxes.remove(&(b, i));
            ans += v;
        }
    }
    ans
}

fn join<T: ToString>(arr: &[T], sep: &str) -> String {
    arr.iter()
        .map(|x| x.to_string())
        .collect::<Vec<String>>()
        .join(sep)
}

Submission Info

Submission Time
Task F - Vouchers
User amoshuangyc
Language Rust (rustc 1.70.0)
Score 500
Code Size 2127 Byte
Status AC
Exec Time 106 ms
Memory 24004 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 19
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 02_handmade_01.txt, 02_handmade_02.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 2092 KiB
00_sample_02.txt AC 1 ms 1948 KiB
01_random_01.txt AC 1 ms 1952 KiB
01_random_02.txt AC 23 ms 8736 KiB
01_random_03.txt AC 47 ms 13272 KiB
01_random_04.txt AC 22 ms 7568 KiB
01_random_05.txt AC 34 ms 12712 KiB
01_random_06.txt AC 105 ms 23872 KiB
01_random_07.txt AC 106 ms 24004 KiB
01_random_08.txt AC 106 ms 23880 KiB
01_random_09.txt AC 106 ms 23864 KiB
01_random_10.txt AC 106 ms 23972 KiB
01_random_11.txt AC 105 ms 23928 KiB
01_random_12.txt AC 105 ms 23932 KiB
01_random_13.txt AC 105 ms 23876 KiB
01_random_14.txt AC 105 ms 24004 KiB
01_random_15.txt AC 106 ms 23872 KiB
02_handmade_01.txt AC 44 ms 18468 KiB
02_handmade_02.txt AC 61 ms 18960 KiB