#![allow(non_snake_case, unused_imports, unused_must_use)] use std::cmp::Reverse; use std::io::{self, prelude::*}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::>() }; } let N = input!(usize); let M = input!(usize); let A = input!(usize, N); let B = input!(usize, M); let mut hq = std::collections::BinaryHeap::new(); for i in 0..N { hq.push((Ratio::new(A[i], B[0]), Reverse(i), 0)); } for _ in 0..M { let (_, i_rev, j) = hq.pop().unwrap(); let i = i_rev.0; if j + 1 < M { hq.push((Ratio::new(A[i], B[j + 1]), Reverse(i), j + 1)); } writeln!(out, "{}", i + 1); } } struct Ratio { a: usize, b: usize, } impl Ratio { fn new(a: usize, b: usize) -> Self { return Self { a: a, b: b }; } } impl PartialEq for Ratio { fn eq(&self, other: &Self) -> bool { let a1 = self.a; let b1 = self.b; let a2 = other.a; let b2 = other.b; a1 * b2 == a2 * b1 } } impl Eq for Ratio { fn assert_receiver_is_total_eq(&self) {} } impl PartialOrd for Ratio { fn partial_cmp(&self, other: &Self) -> Option { let a1 = self.a; let b1 = self.b; let a2 = other.a; let b2 = other.b; (a1 * b2).partial_cmp(&(a2 * b1)) } } impl Ord for Ratio { fn cmp(&self, other: &Self) -> std::cmp::Ordering { let a1 = self.a; let b1 = self.b; let a2 = other.a; let b2 = other.b; (a1 * b2).cmp(&(a2 * b1)) } } struct Scanner { reader: R, buf_str: Vec, buf_iter: str::SplitWhitespace<'static>, } impl Scanner { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }