use std::io::{read_to_string, stdin}; const DAY_START: usize = 0; const DAY_END: usize = 1440; fn virtual_allocation(spaces: &mut Vec, tasks: &Vec, task_idx: usize) -> bool { if task_idx == tasks.len() { return true; } let task_time = tasks[task_idx]; for i in 0..spaces.len() { if spaces[i] >= task_time { spaces[i] -= task_time; if virtual_allocation(spaces, tasks, task_idx + 1) { return true; } spaces[i] += task_time; } } false } fn main() { let mut temp = read_to_string(stdin()).unwrap(); let mut iter = temp.split_whitespace().map(|x| x.parse::().unwrap()); let n = iter.next().unwrap(); let k = iter.next().unwrap(); let mut pre_tasks = (0..n) .map(|_| (iter.next().unwrap(), iter.next().unwrap())) .collect::>(); pre_tasks.sort_by_key(|&(start, _)| start); let mut times_task_to_add = (0..k).map(|_| iter.next().unwrap()).collect::>(); let mut occupied_time = [false; DAY_END - DAY_START]; for (start, end) in pre_tasks { for time in start..end { occupied_time[time] = true; } } let mut empty_space = vec![]; let mut cumulative = 0; for time in DAY_START..DAY_END { if !occupied_time[time] { cumulative += 1; } else { if cumulative > 0 { empty_space.push(cumulative); } cumulative = 0; } } if cumulative > 0 { empty_space.push(cumulative); } // if virtual_allocation(&mut empty_space, ×_task_to_add, 0) { println!("GOOD"); } else { println!("BAD"); } }