pub mod scanner { pub struct Scanner { buf: Vec<String>, } 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<T: std::str::FromStr>(&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<String> { source .split_whitespace() .rev() .map(String::from) .collect::<Vec<_>>() } } } use crate::scanner::Scanner; use std::{collections::BinaryHeap, io::Write}; fn main() { let mut scanner = Scanner::new(); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); let t: usize = 1; for _ in 0..t { solve(&mut scanner, &mut out); } } #[derive(PartialEq, Eq)] struct P { a: usize, b: usize, i: usize, j: usize, } impl PartialOrd for P { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { let x = self.a * other.b; let y = other.a * self.b; if x == y { other.i.partial_cmp(&self.i) } else { x.partial_cmp(&y) } } } impl Ord for P { fn cmp(&self, other: &Self) -> std::cmp::Ordering { let x = self.a * other.b; let y = other.a * self.b; if x == y { other.i.cmp(&self.i) } else { x.cmp(&y) } } } fn solve(scanner: &mut Scanner, out: &mut std::io::BufWriter<std::io::StdoutLock>) { let n: usize = scanner.next(); let m: usize = scanner.next(); let a = (0..n).map(|_| scanner.next::<usize>()).collect::<Vec<_>>(); let b = (0..m).map(|_| scanner.next::<usize>()).collect::<Vec<_>>(); let mut que = BinaryHeap::new(); for i in 0..n { que.push(P { a: a[i], b: b[0], i, j: 0, }); } for _ in 0..m { let p = que.pop().unwrap(); writeln!(out, "{}", p.i + 1).unwrap(); if p.j < m - 1 { que.push(P { a: a[p.i], b: b[p.j + 1], i: p.i, j: p.j + 1, }); } } }