/* -*- coding: utf-8 -*- * * 2453.cc: No.2453 Seat Allocation - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_M = 100000; /* typedef */ struct Cand { double s; int i, j; Cand() {} Cand(double _s, int _i, int _j): s(_s), i(_i), j(_j) {} bool operator<(const Cand &c) const { return s < c.s || (s == c.s && i > c.i); } }; /* global variables */ int as[MAX_N], bs[MAX_M]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < m; i++) scanf("%d", bs + i); priority_queue q; for (int i = 0; i < n; i++) q.push(Cand((double)as[i] / bs[0], i, 0)); for (int k = 0; k < m; k++) { auto u = q.top(); q.pop(); printf("%d\n", u.i + 1); if (u.j + 1 < m) q.push(Cand((double)as[u.i] / bs[u.j + 1], u.i, u.j + 1)); } return 0; }