結果
問題 | No.568 じゃんじゃん 落とす 委員会 |
ユーザー |
![]() |
提出日時 | 2023-12-17 14:26:01 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 34 ms / 1,000 ms |
コード長 | 2,306 bytes |
コンパイル時間 | 19,769 ms |
コンパイル使用メモリ | 402,076 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-24 14:56:48 |
合計ジャッジ時間 | 16,460 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
use std::io::stdin; const INF: usize = 1000000000; fn main() { let mut input = stdin().lines().map(|s| s.unwrap()); let s = input.next().unwrap(); let mut s = s.split_whitespace(); let n: usize = s.next().unwrap().parse().unwrap(); let m: usize = s.next().unwrap().parse().unwrap(); let mut x = Vec::with_capacity(n); let mut a = Vec::with_capacity(n); let mut b = Vec::with_capacity(n); for line in input.take(n) { let mut line = line.split_whitespace(); let xi: usize = line.next().unwrap().parse().unwrap(); let ai: usize = line.next().unwrap().parse().unwrap(); let bi: usize = line.next().unwrap().parse().unwrap(); x.push(xi); a.push(ai); b.push(bi); } let mut x = x; let a = a; let b = b; let mut by_a: Vec<_> = (0..n).collect(); by_a.sort_by_key(|&i| a[i]); let by_a = by_a; let mut by_b: Vec<_> = (0..n).collect(); by_b.sort_by_key(|&i| b[i]); let by_b = by_b; let mut res = INF; let mut two = 0; let mut three = 0; for xi in &mut x { // のちのループが sa = 0, sb = max から始まるので、全員がちょうど xi + 1 個の問題を解ける *xi += 1; if *xi >= 2 { two += 1; } if *xi >= 3 { three += 1; } } let mut by_a_i = 0; let mut by_b_i = 0; let mut sb = 100001; for sa in 0..100002 { while by_a_i < n && a[by_a[by_a_i]] < sa { let i = by_a[by_a_i]; x[i] -= 1; if x[i] == 1 { two -= 1; } if x[i] == 2 { three -= 1; } by_a_i += 1; } while two < m && sb > 0 { sb -= 1; while by_b_i < n && b[by_b[n - 1 - by_b_i]] >= sb { let i = by_b[n - 1 - by_b_i]; x[i] += 1; if x[i] == 2 { two += 1; } if x[i] == 3 { three += 1; } by_b_i += 1; } } // println!("sa: {}, sb: {}, t: {}", sa, sb, three); if two >= m { res = res.min(three); } } println!("{}", res); }