pub mod scanner { pub struct Scanner { buf: Vec, } impl Scanner { pub fn new() -> Self { Self { buf: vec![] } } pub fn new_from(source: &str) -> Self { let source = String::from(source); let buf = Self::split(source); Self { buf } } pub fn next(&mut self) -> T { loop { if let Some(x) = self.buf.pop() { return x.parse().ok().expect(""); } let mut source = String::new(); std::io::stdin().read_line(&mut source).expect(""); self.buf = Self::split(source); } } fn split(source: String) -> Vec { source .split_whitespace() .rev() .map(String::from) .collect::>() } } } use crate::scanner::Scanner; use std::collections::*; fn main() { let mut scanner = Scanner::new(); let t = 1; for _ in 0..t { solve(&mut scanner); } } fn solve(scanner: &mut Scanner) { let n: usize = scanner.next(); let k: usize = scanner.next(); let q: usize = scanner.next(); let mut que1 = VecDeque::new(); for _ in 0..q { let p: usize = scanner.next(); if p == 1 { let s: String = scanner.next(); que1.push_back(s); } else { let mut ans = (0, 0); let mut flag = true; let mut que2 = VecDeque::new(); for _ in 0..6 { let t: String = scanner.next(); let d: usize = scanner.next(); let mut time = d; for past in que1.clone() { if past == t { time = time.min(k); break; } } if ans.0 + time <= 60 && flag { ans.0 += time; ans.1 += 1; que2.push_back(t); } else { flag = false; } } println!("{}", ans.1); for past in que2.clone() { que1.push_back(past); } } while que1.len() > n { que1.pop_front(); } } }