結果
| 問題 |
No.1430 Coup de Coupon
|
| コンテスト | |
| ユーザー |
Strorkis
|
| 提出日時 | 2021-03-14 20:28:10 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 2,000 ms |
| コード長 | 1,788 bytes |
| コンパイル時間 | 14,266 ms |
| コンパイル使用メモリ | 383,248 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 09:22:33 |
| 合計ジャッジ時間 | 15,334 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
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 dp = vec![1 << 30; n + 1];
dp[0] = 0;
let mut sum = 0;
for (i, p) in items.into_iter().enumerate() {
let mut ndp = vec![1 << 30; n + 1];
if i >= c {
sum += p;
continue;
}
for c1 in (0..=i.min(len1)).rev() {
let c2 = i - c1;
if c2 > len2 {
break;
}
let now = dp[c1];
if c1 < len1 {
let next = now + (p - coupons[0][c1]).max(0);
let value = &mut ndp[c1 + 1];
*value = (*value).min(next);
}
if c2 < len2 {
let next = now + p / 100 * (100 - coupons[1][c2]);
let value = &mut ndp[c1];
*value = (*value).min(next);
}
}
dp = ndp;
}
let ans = dp.iter().min().unwrap() + sum;
println!("{}", ans);
}
Strorkis