/* -*- 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 */ typedef long long ll; struct Cand { int i, j, a, b; Cand() {} Cand(int _i, int _j, int _a, int _b): i(_i), j(_j), a(_a), b(_b) {} bool operator<(const Cand &c) const { ll ab0 = (ll)a * c.b, ab1 = (ll)c.a * b; return ab0 < ab1 || (ab0 == ab1 && 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(i, 0, as[i], bs[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(u.i, u.j + 1, as[u.i], bs[u.j + 1])); } return 0; }