#include #ifdef LOCAL #include #else #define debug(...) void(0) #endif template class Rational { T num, den; static T my_gcd(T x_, T y_) { unsigned long long x = x_ < 0 ? -x_ : x_, y = y_ < 0 ? -y_ : y_; if (!x or !y) return x + y; int n = __builtin_ctzll(x), m = __builtin_ctzll(y); x >>= n, y >>= m; while (x != y) { if (x > y) x = (x - y) >> __builtin_ctzll(x - y); else y = (y - x) >> __builtin_ctzll(y - x); } return x << (n > m ? m : n); } void normalize() { if (den < 0) num = -num, den = -den; if (den == 0) num = (num > 0 ? 1 : num < 0 ? -1 : 0); if constexpr (Reduce) { T g = my_gcd(num, den); if (g > 0) num /= g, den /= g; } } public: Rational() {} Rational(T num) : num(num), den(T(1)) {} Rational(T num, T den) : num(num), den(den) { normalize(); } Rational operator+(const Rational& r) const { return Rational(num * r.den + den * r.num, den * r.den); } Rational operator-(const Rational& r) const { return Rational(num * r.den - den * r.num, den * r.den); } Rational operator*(const Rational& r) const { return Rational(num * r.num, den * r.den); } Rational operator/(const Rational& r) const { return Rational(num * r.den, den * r.num); } Rational& operator+=(const Rational& r) { return *this = *this + r; } Rational& operator-=(const Rational& r) { return *this = *this - r; } Rational& operator*=(const Rational& r) { return *this = *this * r; } Rational& operator/=(const Rational& r) { return *this = *this / r; } Rational operator+(const T& val) const { return *this + Rational(val); } Rational operator-(const T& val) const { return *this - Rational(val); } Rational operator*(const T& val) const { return *this * Rational(val); } Rational operator/(const T& val) const { return *this / Rational(val); } Rational& operator+=(const T& val) { return *this = *this + val; } Rational& operator-=(const T& val) { return *this = *this - val; } Rational& operator*=(const T& val) { return *this = *this * val; } Rational& operator/=(const T& val) { return *this = *this / val; } friend Rational operator+(const T& val, const Rational& r) { return r + val; } friend Rational operator-(const T& val, const Rational& r) { return r - val; } friend Rational operator*(const T& val, const Rational& r) { return r * val; } friend Rational operator/(const T& val, const Rational& r) { return r / val; } Rational operator-() const { return Rational(-num, den); } Rational abs() const { return Rational(num < 0 ? -num : num, den); } bool operator==(const Rational& r) const { if (den == 0 and r.den == 0) return num == r.num; if (den == 0 or r.den == 0) return false; return num * r.den == den * r.num; } bool operator!=(const Rational& r) const { return !(*this == r); } bool operator<(const Rational& r) const { if (den == 0 and r.den == 0) return num < r.num; if (den == 0) return num < 0; if (r.den == 0) return r.num > 0; return num * r.den < den * r.num; } bool operator<=(const Rational& r) const { return (*this == r) or (*this < r); } bool operator>(const Rational& r) const { return r < *this; } bool operator>=(const Rational& r) const { return (*this == r) or (*this > r); } bool operator==(const T& val) const { return *this == Rational(val); } bool operator!=(const T& val) const { return *this != Rational(val); } bool operator<(const T& val) const { return *this < Rational(val); } bool operator<=(const T& val) const { return *this <= Rational(val); } bool operator>(const T& val) const { return *this > Rational(val); } bool operator>=(const T& val) const { return *this >= Rational(val); } friend bool operator==(const T& val, const Rational& r) { return r == val; } friend bool operator!=(const T& val, const Rational& r) { return r != val; } friend bool operator<(const T& val, const Rational& r) { return r > val; } friend bool operator<=(const T& val, const Rational& r) { return r >= val; } friend bool operator>(const T& val, const Rational& r) { return r < val; } friend bool operator>=(const T& val, const Rational& r) { return r <= val; } explicit operator double() const { return (double)num / (double)den; } explicit operator long double() const { return (long double)num / (long double)den; } friend std::ostream& operator<<(std::ostream& os, const Rational& r) { return os << r.num << '/' << r.den; } }; using namespace std; typedef long long ll; #define all(x) begin(x), end(x) constexpr int INF = (1 << 30) - 1; constexpr long long IINF = (1LL << 60) - 1; constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; template istream& operator>>(istream& is, vector& v) { for (auto& x : v) is >> x; return is; } template ostream& operator<<(ostream& os, const vector& v) { auto sep = ""; for (const auto& x : v) os << exchange(sep, " ") << x; return os; } template bool chmin(T& x, U&& y) { return y < x and (x = forward(y), true); } template bool chmax(T& x, U&& y) { return x < y and (x = forward(y), true); } template void mkuni(vector& v) { sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); } template int lwb(const vector& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); } using R = Rational; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector A(N), B(M); cin >> A >> B; priority_queue> pq; vector cur(N, 0); for (int i = 0; i < N; i++) pq.emplace(R(A[i], B[cur[i]++]), -i); for (int i = 0; i < M; i++) { auto [val, idx] = pq.top(); pq.pop(); idx *= -1; cout << idx + 1 << '\n'; if (cur[idx] < M) pq.emplace(R(A[idx], B[cur[idx]++]), -idx); } return 0; }