Problem:
Code Art Online
G: コードアートオンライン
コードアートオンライン（CAO）は，様々な問題をプログラミングによって解くことにより，冒険を進めて行くオンラインRPGである．
CAOは，世界初のバーチャルリアリティ空間を実現したゲームであったこともあり，大人気の内に完売し，ゲームを購入したユーザ達はこの世界を楽しむはずであった．
しかし，ゲームにダイブしたプレイヤー達は，ゲームマスターから恐るべき託宣を聞かされる．
「君たちプレイヤーの内の誰かが，ラストダンジョンのラストプロブレムを解かない限り，この仮想空間から抜け出すことはできない．そして，この世界での，WAやTLE・REは，現実世界での死を意味する．心して問題にとりかかってほしい．」
あなたも，CAOのプレイヤーの内の1人で，このゲームをクリアして現実世界に戻るために，ゲーム攻略に全力を尽くしている．
ある日，あなたは次のような問題に直面することとなった．
今回，新たなダンジョンを攻略するために，
n
人のメンバーでパーティが組まれた．
あなたもこのパーティの内の1人である．
今から攻略するダンジョンに突入するためには，崖から見える穴を通過しなくてはならない．
無事に穴を通過できれば，ダンジョンに突入できるが，穴に突入できず他の部分に触れてしまうと，死が待っている．
さらに，1つの穴に誰かが通ると，その穴は閉じてしまうため，1人1人別々の穴に入らなければならない．
穴や人は，二次元平面上で考えることとする．
穴の形は，図G-1のような，大小様々な円である．入力では，半径の長さが与えられる．
図G-1: 穴の形
人の形は，図G-2のように人の断面が多角形で与えられる（凸とは限らない）．
入力では，多角形の形を表すために，頂点が反時計まわりで与えられる．
多角形の任意の三点は，1直線上に並ばないと仮定してよい．
さらに，頂点を構成する目的以外で，多角形の線分同士が交差することはないものとする．
穴に通すために，自由に回転してよい（ただし，z軸方向への回転は禁止する）．
人を表す多角形の頂点が，穴の円周上にある場合でも，穴を通過できるものとする．
図G-2: 人の形
パーティの中で最もアルゴリズムスキルが高いあなたは，みんなで無事に穴を通過できるかどうかの判定問題を解くことにした．
もし，無事に通過できるなら，どの人がどの穴を通過すればいいのか表示せよ．
※今回のコンテストで死ぬことはありませんが，間違ったら死ぬつもりで解いてください．
Input
1行目に，穴の数を表す整数
n
(1 <=
n
<= 100)と，パーティの人数を表す整数
m
(1 <=
m
<=
n
)がスペース区切りで入力される．
次の行に，穴の半径を表す整数
r
i
(1 <=
r
i
<= 1000)がスペース区切りで
n
個入力される．
これらの穴は，入力された順番に，1番の穴, 2番の穴, ...,
n
番の穴と数えることとする．
続いて，
m
人の人の形の情報が入力される．
1人の情報は，まず1行目に多角形の頂点数
p
(3 <=
p
<= 100)が入力される．
続く
p
行には，多角形の頂点の座標が反時計周りで与えられる．
各行には，1つの頂点を表す整数
x
i
,
y
i
(-1000 <=
x
i
,
y
i
<= 1000)がスペース区切りで入力される．
人は，入力された順番に，1番の人, 2番の人, ...,
m
番の人と数えることとする．
Output
i
番(1 <=
i
<=
m
)の人が，何番の穴に入ればいいかを出力せよ．
i
行目には，
i
番の人が通るべき穴の番号を出力すること．
もし，複数の通り方がある場合，辞書順で一番小さくなる通り方を出力すること．
2つの数列
A
= {
a
1
,
a
2
, ...,
a
m
}と
B
= {
b
1
,
b
2
, ...,
b
m
}があったとき，
A
が
B
より辞書順で小さいとは，
a
i
が
b
i
と異なるような最初の
i
について，
a
i
が
b
i
より小さいときのことを言う．
通り方が1つも見つからない場合は，"NG"と1行出力すること．
最後に改行を出力するのを忘れないこと．
Sample Input 1
3 3
25 100 10
8
-10 0
-2 2
0 10
2 2
10 0
2 -2
0 -10
-2 -2
4
30 0
50 0
50 40
30 40
3
30 -10
45 -70
60 -10
Sample Output 1
3
1
2
Sample Input 2
4 3
25 15 15 30
5
0 0
10 0
20 10
0 20
-20 10
3
20 0
40 0
30 10
3
-50 0
-30 0
-40 10
Sample Output 2
1
2
3
Sample Input 3
2 2
1 30
4
0 0
10 0
10 10
0 10
3
5 5
20 20
5 20
Sample Output 3
NG

Submitted solutions:

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 170
memory_kb: 3580
final_rank: 15

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 100) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 3596
final_rank: 3

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 170
memory_kb: 3596
final_rank: 17

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 70
memory_kb: 3600
final_rank: 11

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3604
final_rank: 14

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 170
memory_kb: 3584
final_rank: 16

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3600
final_rank: 13

code_snippet: #pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 70
memory_kb: 3592
final_rank: 6

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3596
final_rank: 9

code_snippet: #pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 70
memory_kb: 3600
final_rank: 11

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3592
final_rank: 8

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3596
final_rank: 9

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define each(e, c) for (auto &e : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define curr(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define self (*this)
typedef long double R;
const R eps = 1e-10;
const R inf = 1e12;
const R pi = acos(-1);
typedef complex<R> P;
R arg(P a, P b, P c) {
  R th = arg((a - b) / (c - b));
  return th > 0 ? th : th + 2 * pi;
}
bool comp_x(P const &a, P const &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool comp_y(P const &a, P const &b) {
  return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
P CENTER = P();
bool comp_arg(P const &a, P const &b) {
  return arg(a, CENTER, CENTER + (R)1.) < arg(b, CENTER, CENTER + (R)1.);
}
namespace std {
bool operator<(P const &a, P const &b) { return comp_x(a, b); }
} // namespace std
R cross(P const &a, P const &b) { return imag(conj(a) * b); }
R dot(P const &a, P const &b) { return real(conj(a) * b); }
struct L : public vector<P> {
  L(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L(R a, R b, R c) {
    if (fabs(a) < eps)
      self = L(P(0, -c / b), P(1, -c / b));
    else if (fabs(b) < eps)
      self = L(P(-c / a, 0), P(-c / a, 1));
    else
      self = L(P(-c / a, 0), P(0, -c / b));
  }
  P vec() const { return self[1] - self[0]; }
};
struct S : public vector<P> {
  S(P const &a = P(), P const &b = P()) {
    push_back(a);
    push_back(b);
  }
  L line() const { return L(self[0], self[1]); }
  P vec() const { return line().vec(); }
  R len() const { return abs(vec()); }
};
typedef vector<P> G;
struct C {
  P p;
  R r;
  C(P const &p = P(), R r = 0) : p(p), r(r) {}
};
enum { CCW = +1, CW = -1, CAB = +2, ABC = -2, SEG = 0 };
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return CCW;
  if (cross(b, c) < 0)
    return CW;
  if (dot(b, c) < 0)
    return CAB;
  if (norm(b) < norm(c))
    return ABC;
  return SEG;
}
R area(C const &c) { return pi * c.r * c.r; }
R area(G const &g) {
  R res = 0;
  int n = g.size();
  rep(i, n) res += cross(g[i], g[(i + 1) % n]);
  return abs(res) / 2;
}
R heron(R a, R b, R c) {
  R s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
P biased_center(P const &a, P const &b, P const &c, R wa, R wb, R wc) {
  return (wa * a + wb * b + wc * c) / (wa + wb + wc);
}
P gravity_center(P const &a, P const &b, P const &c) {
  return biased_center(a, b, c, 1, 1, 1);
}
P inner_center(P const &a, P const &b, P const &c) {
  R la = abs(b - c), lb = abs(c - a), lc = abs(a - b);
  return biased_center(a, b, c, la, lb, lc);
}
P circumcenter(P const &a, P const &b, P const &c) {
  R sa = sin(2 * arg(c, a, b)), sb = sin(2 * arg(a, b, c)),
    sc = sin(2 * arg(b, c, a));
  return biased_center(a, b, c, sa, sb, sc);
}
P orthocenter(P const &a, P const &b, P const &c) {
  if (abs(arg(c, a, b)) == pi)
    return a;
  if (abs(arg(a, b, c)) == pi)
    return b;
  if (abs(arg(b, c, a)) == pi)
    return c;
  R ta = tan(arg(c, a, b)), tb = tan(arg(a, b, c)), tc = tan(arg(b, c, a));
  return biased_center(a, b, c, ta, tb, tc);
}
P excenter(P const &a, P const &b, P const &c) {
  R sa = sin(arg(c, a, b)), sb = sin(arg(a, b, c)), sc = sin(arg(b, c, a));
  return biased_center(a, b, c, -sa, sb, sc);
}
bool col(L const &l, L const &m) {
  return abs(cross(l.vec(), m.vec())) > eps ||
         abs(cross(l.vec(), m[0] - l[0])) < eps;
}
bool col(L const &l, S const &s) {
  return cross(l.vec(), s[0] - l[0]) * cross(l.vec(), s[1] - l[0]) < eps;
}
bool col(S const &s, L const &l) { return col(l, s); }
bool col(L const &l, P const &p) {
  return abs(cross(l[1] - p, l[0] - p)) < eps;
}
bool col(P const &p, L const &l) { return col(l, p); }
bool col(const S &s, const S &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool col(const S &s, const P &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps;
}
int col(const C &c1, const C &c2) {
  R d = abs(c1.p - c2.p), r1 = c1.r, r2 = c2.r;
  if (r1 + r2 < d)
    return 0;
  if (abs(r1 + r2 - d) < eps)
    return 1;
  if (abs(d - abs(r1 - r2)) < eps)
    return -1;
  if (d < r1 - r2)
    return +3;
  if (d < r2 - r1)
    return -3;
  return 2;
}
P proj(L const &l, P const &p) {
  R t = dot(p - l[0], l.vec()) / norm(l.vec());
  return l[0] + t * (l.vec());
}
P proj(P const &p, L const &l) { return proj(l, p); }
P refl(L const &l, P const &p) { return p + (R)2 * (proj(l, p) - p); }
P refl(P const &p, L const &l) { return refl(l, p); }
R dist(P const &p, P const &q) { return abs(p - q); }
R dist(L const &l, P const &p) { return abs(p - proj(l, p)); }
R dist(P const &p, L const &l) { return dist(l, p); }
R dist(L const &l, L const &m) { return col(l, m) ? 0 : dist(l, m[0]); }
R dist(L const &l, S const &s) {
  return col(l, s) ? 0 : min(dist(l, s[0]), dist(l, s[1]));
}
R dist(S const &s, L const &l) { return dist(l, s); }
R dist(S const &s, P const &p) {
  P const r = proj(s.line(), p);
  return col(s, r) ? abs(r - p) : min(abs(s[0] - p), abs(s[1] - p));
}
R dist(P const &p, S const &s) { return dist(s, p); }
R dist(S const &s, S const &t) {
  return col(s, t) ? 0
                   : min(min(min(dist(s, t[0]), dist(s, t[1])), dist(t, s[0])),
                         dist(t, s[1]));
}
vector<P> hit(L const &l, L const &m) {
  R A = cross(l.vec(), m.vec());
  R B = cross(l.vec(), l[1] - m[0]);
  if (abs(A) < eps && abs(B) < eps)
    return {m[0]};
  if (abs(A) < eps)
    return G();
  return {m[0] + B / A * (m.vec())};
}
vector<P> hit(S const &s, S const &t) {
  return col(s, t) ? hit(s.line(), t.line()) : G();
}
vector<P> hit(L const &l, S const &s) {
  return col(l, s) ? hit(l, s.line()) : G();
}
vector<P> hit(S const &s, L const &l) { return hit(l, s); }
vector<P> hit(C const &c, L const &l) {
  R d = dist(l, c.p);
  if (fabs(d - c.r) < eps)
    return {proj(l, c.p)};
  if (d > c.r)
    return G();
  P h = proj(l, c.p);
  P u = sqrt(c.r * c.r - d * d) * (l.vec()) / abs(l.vec());
  return {h + u, h - u};
}
vector<P> hit(C const &c, S const &s) {
  G cps = hit(c, s.line()), res;
  for (const P &p : cps)
    if (col(s, p))
      res.push_back(p);
  return res;
}
vector<P> hit(C const &c1, C const &c2) {
  if (abs(c1.p - c2.p) < 0)
    return G();
  int i = col(c1, c2);
  if (i == 0 || abs(i) == 3)
    return G();
  R r1 = c1.r, r2 = c2.r, d = abs(c1.p - c2.p);
  if (i == 1)
    return {c1.p + (c2.p - c1.p) * r1 / d};
  P p = c1.p - c2.p;
  R A = -2. * p.real(), B = 2 * p.imag();
  R C = norm(c1.p) - norm(c2.p) - r1 * r1 + r2 * r2;
  return hit(c1, L(A, B, C));
}
vector<P> hit(C const &c, G const &g) {
  vector<P> res;
  int n = g.size();
  rep(i, n) for (P const &p : hit(c, S(g[i], g[(i + 1) % n]))) res.push_back(p);
  return res;
}
C min_ball(G const &g) {
  int n = g.size();
  if (n == 1)
    return C(g[0], 0);
  if (n == 2)
    return C((g[0] + g[1]) / (R)2, abs((g[0] + g[1]) / (R)2 - g[0]));
  P c = (g[0] + g[n / 3] + g[n / 3 * 2]) / (R)3;
  R r = 1.0;
  rep(i, 1000) {
    R d = 0;
    int x = 0;
    rep(j, n) {
      if (d < abs(g[j] - c)) {
        d = abs(g[j] - c);
        x = j;
      }
    }
    c += (g[x] - c) * r;
    if (i & 2)
      r *= 0.8;
  }
  R d = -1;
  int x = 0;
  rep(i, n) {
    if (d < abs(c - g[i])) {
      d = abs(c - g[i]);
      x = i;
    }
  }
  return C(c, abs(c - g[x]));
}
int n, m;
R r[111], mb[111];
vi ans;
bool used[111];
bool chk(int s) {
  vi b;
  rep(i, n) if (!used[i]) b.eb(r[i]);
  vector<R> a;
  loop(i, s, m) a.eb(mb[i]);
  sort(all(a));
  sort(all(b));
  int last = -1;
  rep(i, a.size()) {
    bool found = false;
    loop(j, last + 1, b.size()) {
      if (a[i] < b[j] + eps) {
        found = true;
        last = j;
        break;
      }
    }
    if (!found)
      return false;
  }
  return true;
}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  while (cin >> n >> m) {
    ans.clear();
    rep(i, n) cin >> r[i];
    rep(i, m) {
      int k;
      cin >> k;
      G g(k);
      rep(j, k) {
        R x, y;
        cin >> x >> y;
        g[j] = P(x, y);
      }
      mb[i] = min_ball(g).r;
    }
    rep(i, m) used[i] = false;
    bool f = true;
    rep(i, m) {
      bool found = false;
      rep(j, n) {
        if (used[j])
          continue;
        if (!(mb[i] < r[j] + eps))
          continue;
        used[j] = true;
        if (chk(i + 1)) {
          ans.push_back(j);
          found = true;
          break;
        }
        used[j] = false;
      }
      if (!found) {
        f = false;
        break;
      }
    }
    if (f) {
      rep(i, m) cout << ans[i] + 1 << "\n";
    } else
      cout << "NG" << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3588
final_rank: 5

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 205

struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{

		if(fabs(x-p.x) > EPS){

			return x < p.x;
		}else{

			return y < p.y;
		}
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}


	void debug(){

		printf("(%.3lf,%.3lf)\n",x,y);
	}

	double x,y;
};


struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		rev_index = arg_rev_index;
	}
	int to,capacity,rev_index;
};

typedef Point Vector;
typedef vector<Point> Polygon;



int N,M;
int work[SIZE],ANS[SIZE];
double R[SIZE],need_R[SIZE];
bool FLG,check[SIZE];
Polygon POLY[SIZE];

int C_INDEX[SIZE];

int V;
vector<Edge> G[SIZE];
int dist[SIZE];
int cheked_index[SIZE];



double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}

double calc(double x,double y,int index){

	Point base = Point(x,y);

	double ret = 0;

	for(int i = 0; i < POLY[index].size(); i++){

		double tmp_dist = calc_dist(base,POLY[index][i]);
		ret = max(ret,tmp_dist);
	}

	return ret;
}

double thirds_searchY(double X,int index){

	double L = -1001,R = 1001;

	for(int loop = 0; loop < 100; loop++){

		double mid1 = (2.0*L+R)/3.0;
		double mid2 = (1.0*L+2.0*R)/3.0;

		if(calc(X,mid1,index) > calc(X,mid2,index)){

			L = mid1;
		}else{

			R = mid2;
		}
	}

	return calc(X,(L+R)/2,index);
}

double thirds_searchX(int index){

	double L = -1001,R = 1001;

	for(int loop = 0; loop < 100; loop++){

		double mid1 = (2.0*L+R)/3.0;
		double mid2 = (1.0*L+2.0*R)/3.0;

		if(thirds_searchY(mid1,index) > thirds_searchY(mid2,index)){

			L = mid1;
		}else{

			R = mid2;
		}
	}

	return thirds_searchY((L+R)/2,index);
}



void add_edge(int from,int to,int capacity){
	G[from].push_back(Edge(to,capacity,G[to].size()));
	G[to].push_back(Edge(from,0,G[from].size()-1));
}


//sourceからの最短距離をBFSで計算する
void bfs(int source){
	for(int i = 0; i < V; i++)dist[i] = -1;
	queue<int> Q;
	dist[source] = 0;
	Q.push(source);

	while(!Q.empty()){
		int node_id = Q.front();
		Q.pop();
		for(int i = 0; i < G[node_id].size(); i++){
			Edge &e = G[node_id][i];
			if(e.capacity > 0 && dist[e.to] < 0){ //辺の容量が正で、かつエッジの行先に未訪問の場合
				dist[e.to] = dist[node_id]+1;
				Q.push(e.to);
			}
		}
	}
}

//増加パスをDFSで探す
int dfs(int node_id,int sink,int flow){
	if(node_id == sink)return flow; //終点についたらflowをreturn

	for(int &i = cheked_index[node_id]; i < G[node_id].size(); i++){ //node_idから出ているエッジを調査
		Edge &e = G[node_id][i];
		if(e.capacity > 0 && dist[node_id] < dist[e.to]){ //流せる余裕があり、かつsourceからの距離が増加する方法である場合
			int tmp_flow = dfs(e.to,sink,min(flow,e.capacity)); //流せるだけ流す
			if(tmp_flow > 0){ //流せた場合
				e.capacity -= tmp_flow; //流した分、エッジの容量を削減する
				G[e.to][e.rev_index].capacity += tmp_flow; //逆辺の容量を、流した分だけ増加させる
				return tmp_flow;
			}
		}
	}
	return 0;
}


//sourceからsinkへの最大流を求める
int max_flow(int source,int sink){ //source:始点 sink:終点
	int flow = 0,add;
	while(true){ //増加パスが存在する限り、流量を追加し続ける
		bfs(source);
		if(dist[sink] < 0)break; //sourceからsinkへと辿り着く残余グラフがない、つまり増加パスが無くなった場合、break
		for(int i = 0; i < V; i++)cheked_index[i] = 0;
		while((add = dfs(source,sink,BIG_NUM)) > 0){ //増加パスが見つかる間、加算
			flow += add;
		}
	}
	return flow;
}


void delete_edge(int from,int index){

	//ノーマル辺を消す
	G[from][index].capacity = 0;
	int rev_from = G[from][index].to;

	//逆辺を消す
	int left = 0,right = G[rev_from].size()-1,mid = (left+right)/2;

	while(left <= right){

		if(G[rev_from][mid].to == from){

			G[rev_from][mid].capacity = 0;
			return;

		}else if(G[rev_from][mid].to > from){

			right = mid-1;

		}else{
			left = mid+1;
		}
		mid = (left+right)/2;
	}
}

bool find_a_path(int source,int sink){ //sourceからsinkへの増加パスがあるか調べる

	bfs(source);

	if(dist[sink] < 0){
		return false; //増加パスがなければfalse
	}

	for(int i = 0; i < V; i++)cheked_index[i] = 0;

	return dfs(source,sink,1) == 1; //sourceからsinkに1流せるか調べる
}

int main(){


	scanf("%d %d",&N,&M);

	for(int i = 0; i < N; i++){

		scanf("%lf",&R[i]);
	}


	int source = N+M,sink = source+1;
	V = N+M+2;

	for(int i = 0; i < M; i++){

		add_edge(source,i,1);
	}

	for(int i = 0; i < N; i++){

		C_INDEX[i] = M+i;
		add_edge(C_INDEX[i],sink,1);
	}

	int num_P;
	double x,y;

	for(int i = 0; i < M; i++){

		scanf("%d",&num_P);
		for(int k = 0; k < num_P; k++){

			scanf("%lf %lf",&x,&y);
			POLY[i].push_back(Point(x,y));
		}

		need_R[i] = thirds_searchX(i);
	}

	//辺張り
	for(int i = 0; i < M; i++){
		for(int k = 0; k < N; k++){
			if(need_R[i] <= R[k]+EPS){

				add_edge(i,C_INDEX[k],1);
			}
		}
	}


	if(max_flow(source,sink) < M){

		printf("NG\n");
		return 0;
	}

	for(int k = 0; k < M; k++){

		//番号の大きい部品から、降順に見ていく
		for(int i = G[k].size()-1; i >= 0; i--){

			if(G[k][i].capacity == 1){ //エッジに流れていない場合

				delete_edge(k,i); //流れないように、辺を論理削除

			}else{ //エッジに流れている場合

				//★残余グラフ上で別の経路がないか試す★
				if(find_a_path(k,G[k][i].to)){

					delete_edge(k,i); //より小さい番号の部品とマッチできるので、辺を論理削除

				}else{ //流せない:辺確定

					printf("%d\n",G[k][i].to+1-M);
					break;
				}
			}
		}
	}

	return 0;
}
accuracy: 1
time_ms: 780
memory_kb: 3388
final_rank: 18

code_snippet: #include <iostream>
#include <array>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <math.h>
#include <string>
#include <climits>
#include <assert.h>
#include <iomanip>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <fstream>
#include <random>

#define LEN(x) (long long)(x.size())
#define FOR(i, a, n) for(int i=(a);i<(n); ++i)
#define FOE(i, a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_COUNT(bit) (__builtin_popcount(bit))

using LL = long long;

template<typename T>
std::vector<T> make_v(size_t a) { return std::vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }    // C++14
template<typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename std::enable_if<std::is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e:t) fill_v(e, v); }

template<class T>
inline T ceil(T a, T b) { return (a + b - 1) / b; }

void print() { std::cout << std::endl; }

template<class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    std::cout << head;
    if (sizeof...(tail) != 0) { std::cout << " "; }
    print(std::forward<Tail>(tail)...);
}

template<class T>
void print(std::vector<T> &v) {
    for (auto &a : v) {
        std::cout << a;
        if (&a != &v.back()) { std::cout << " "; }
    }
    std::cout << std::endl;
}

template<class T>
void print(std::vector<std::vector<T>> &vv) { for (auto &v : vv) { print(v); }}

void debug() { std::cerr << std::endl; }

template<class Head, class... Tail>
void debug(Head &&head, Tail &&... tail) {
    std::cerr << head;
    if (sizeof...(tail) != 0) { std::cerr << " "; }
    print(std::forward<Tail>(tail)...);
}

template<class T>
void debug(std::vector<T> &v) {
    for (auto &a : v) {
        std::cerr << a;
        if (&a != &v.back()) { std::cerr << " "; }
    }
    std::cerr << std::endl;
}

template<class T>
void debug(std::vector<std::vector<T>> &vv) { for (auto &v : vv) { print(v); }}

inline bool inside(long long y, long long x, long long H, long long W) { return 0 <= y and y < H and 0 <= x and x < W; }

template<class T>
inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }

template<class T>
inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

template<typename T>
T &chmin(T &a, const T &b) { return a = std::min(a, b); }

template<typename T>
T &chmax(T &a, const T &b) { return a = std::max(a, b); }

bool is_bit_on(const unsigned long long bit, const unsigned int i) { return (bit >> i) & 1u; }

unsigned long long bit_set(const unsigned long long bit, const unsigned int i, const unsigned int b) {
    assert(b == 0 or b == 1);
    if (b == 0) { return bit & ~(1ull << i); }
    else { return bit | (1ull << i); }
}

// 初項s交差d長さnの数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

// xが2の階乗かどうか判定
bool is_power_of_two(long long x) {
    return !(x & (x - 1));
}

long long gcd(long long a, long long b) {
    if (b == 0) { return a; }
    return gcd(b, a % b);
}

long long gcd(std::vector<long long> &v) {
    long long ans = v[0];
    for (int i = 1; i < (int) v.size(); ++i) {
        ans = gcd(ans, v[i]);
    }
    return ans;
}

long long lcm(long long a, long long b) {
    long long g = gcd(a, b);
    return a / g * b;
}

const int INF = 1u << 30u;  // 1,073,741,824
const long long LINF = 1ull << 60u;
const double EPS = 1e-9;
const long double PI = acos(-1.0);
const std::vector<int> dy2 = {0, 1}, dx2 = {1, 0};
const std::vector<int> dy4 = {0, 1, 0, -1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = {0, -1, 0, 1, 1, -1, -1, 1}, dx8 = {1, 0, -1, 0, 1, 1, -1, -1};

class Point {
public:
    double x;
    double y;

    Point(): x(0), y(0) {}
    Point(double x, double y) : x(x), y(y) {}
};

class SmallestEnclosingCircle {
private:
    double min_x;
    double max_x;
    double min_y;
    double max_y;

public:
    SmallestEnclosingCircle() {}

    // 最小包含円の半径
    double solve(const std::vector<Point> &points) {
        this->min_x = this->max_x = points[0].x;
        this->min_y = this->max_y = points[0].y;

        for (const auto &p : points) {
            this->min_x = std::min(this->min_x, p.x);
            this->max_x = std::max(this->max_x, p.x);
            this->min_y = std::min(this->min_y, p.y);
            this->max_y = std::max(this->max_y, p.y);
        }

        double l = this->min_x - 1.0;
        double r = this->max_x + 1.0;

        // x座標で3分探索
        for (int _ = 0; _ < 100; ++_) {
            const double c1 = (l * 2 + r) / 3.0;
            const double c2 = (l + r * 2) / 3.0;

            if (g(c1, points) > g(c2, points)) {
                l = c1;
            } else {
                r = c2;
            }
        }

        return g(l, points);
    }

private:

    // 点aと点bの距離
    double dist(const Point &a, const Point &b) {
        double dx = a.x - b.x;
        double dy = a.y - b.y;
        return sqrt(dx * dx + dy * dy);
    }

    // nowから最も遠い点までの距離
    double max_distance(const Point &now, const std::vector<Point> &points) {
        double res = 0;
        for (const auto p : points) {
            res = std::max(res, dist(now, p));
        }
        return res;
    }

    // x座標を決めたときの，y軸の距離を最小化
    double g(const double x, const std::vector<Point> &points) {
        double l = this->min_y - 1.0;
        double r = this->max_y + 1.0;

        for (int _ = 0; _ < 100; ++_) {
            double c1 = (l * 2 + r) / 3;
            double c2 = (l + r * 2) / 3;

            if (max_distance(Point(x, c1), points) > max_distance(Point(x, c2), points)) {
                l = c1;
            } else {
                r = c2;
            }
        }

        return max_distance(Point(x, l), points);
    }
};

using namespace std;

// iさんをhole[j]に割り当てられるか
bool can_assign(int i, int j, vector<bool> &used, vector<double> &holes, vector<double> &dists) {
    vector<double> rest_dists;
    for (int k = i + 1; k < dists.size(); ++k) {
        rest_dists.emplace_back(dists[k]);
    }
    sort(rest_dists.rbegin(), rest_dists.rend());

    vector<double> rest_holes;
    for (int k = 0; k < (int)holes.size(); ++k) {
        if (k != j and not used[k]) {
            rest_holes.emplace_back(holes[k]);
        }
    }
    sort(rest_holes.rbegin(), rest_holes.rend());

    assert(rest_holes.size() >= rest_dists.size());
    for (int k = 0; k < rest_dists.size(); ++k) {
        if (rest_holes[k] < rest_dists[k]) {
            return false;
        }
    }

    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, M;
    cin >> N >> M;
    vector<double> holes(N);
    for (int i = 0; i < N; ++i) {
        cin >> holes[i];
    }

    vector<double> dist(M);
    for (int i = 0; i < M; ++i) {
        int P;
        cin >> P;
        vector<Point> points(P);

        for (int j = 0; j < P; ++j) {
            cin >> points[j].x >> points[j].y;
        }

        SmallestEnclosingCircle sec;
        dist[i] = sec.solve(points) - EPS;
    }

    vector<int> ans(M, -1);
    vector<bool> used(N);
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < N; ++j) {
            if (not used[j] and dist[i] <= holes[j]) {
                if (can_assign(i, j, used, holes, dist)) {
                    ans[i] = j;
                    used[j] = true;
                    break;
                }
            }
        }
        if (ans[i] == -1) {
            cout << "NG" << endl;
            return 0;
        }
    }

    for (int i = 0; i < M; ++i) {
        cout << ans[i] + 1 << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 790
memory_kb: 3328
final_rank: 7

code_snippet: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }



using DD = double;
const DD INF = 1LL<<60;      // to be set appropriately
const DD EPS = 1e-6;        // to be set appropriately
const DD PI = acosl(-1.0);
DD torad(int deg) {return (DD)(deg) * PI / 180;}
DD todeg(DD ang) {return ang * 180 / PI;}

/* Point */
struct Point {
    DD x, y;
    Point(DD x = 0.0, DD y = 0.0) : x(x), y(y) {}
    friend ostream& operator << (ostream &s, const Point &p) {return s << '(' << p.x << ", " << p.y << ')';}
};
inline Point operator + (const Point &p, const Point &q) {return Point(p.x + q.x, p.y + q.y);}
inline Point operator - (const Point &p, const Point &q) {return Point(p.x - q.x, p.y - q.y);}
inline Point operator * (const Point &p, DD a) {return Point(p.x * a, p.y * a);}
inline Point operator * (DD a, const Point &p) {return Point(a * p.x, a * p.y);}
inline Point operator * (const Point &p, const Point &q) {return Point(p.x * q.x - p.y * q.y, p.x * q.y + p.y * q.x);}
inline Point operator / (const Point &p, DD a) {return Point(p.x / a, p.y / a);}
inline Point conj(const Point &p) {return Point(p.x, -p.y);}
inline Point rot(const Point &p, DD ang) {return Point(cos(ang) * p.x - sin(ang) * p.y, sin(ang) * p.x + cos(ang) * p.y);}
inline Point rot90(const Point &p) {return Point(-p.y, p.x);}
inline DD cross(const Point &p, const Point &q) {return p.x * q.y - p.y * q.x;}
inline DD dot(const Point &p, const Point &q) {return p.x * q.x + p.y * q.y;}
inline DD norm(const Point &p) {return dot(p, p);}
inline DD abs(const Point &p) {return sqrt(dot(p, p));}
inline DD amp(const Point &p) {DD res = atan2(p.y, p.x); if (res < 0) res += PI*2; return res;}
inline bool eq(const Point &p, const Point &q) {return abs(p - q) < EPS;}
inline bool operator < (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x < q.x : p.y < q.y);}
inline bool operator > (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x > q.x : p.y > q.y);}
inline Point operator / (const Point &p, const Point &q) {return p * conj(q) / norm(q);}

// 最小包含円
const int ITER = 100;

DD f(const vector<Point> &v, DD x, DD y) {
    DD res = 0;
    for (int i = 0; i < v.size(); ++i) res = max(res, abs(v[i] - Point(x, y)));
    return res;
}

DD g(const vector<Point> &v, DD x) {
    DD left = -10000, right = 10000;
    for (int _ = 0; _ < ITER; ++_) {
        DD m1 = (left * 2 + right) / 3;
        DD m2 = (left + right * 2) / 3;
        if (f(v, x, m1) > f(v, x, m2)) left = m1;
        else right = m2;
    }
    return f(v, x, left);
}

DD mic(const vector<Point> &v) {
    DD left = -10000, right = 10000;
    for (int _ = 0; _ < ITER; ++_) {
        DD m1 = (left * 2 + right) / 3;
        DD m2 = (left + right * 2) / 3;
        if (g(v, m1) > g(v, m2)) left = m1;
        else right = m2;
    }
    return g(v, left);
}

// 人がすべてマッチできるか
bool can(vector<DD> person, vector<DD> ana) {
    sort(person.begin(), person.end());
    sort(ana.begin(), ana.end());
    int j = 0;
    for (int i = 0; i < person.size(); ++i) {
        while (j < ana.size() && person[i] > ana[j] + EPS) ++j;
        if (j == ana.size()) return false;
        ++j;
    }
    return true;
}

int main() {
    int N, M; cin >> N >> M;
    vector<pair<DD,int>> r(N), p(M);
    vector<vector<Point>> vp(M);
    for (int i = 0; i < N; ++i) cin >> r[i].first, r[i].second = i;
    for (int i = 0; i < M; ++i) {
        int a; cin >> a;
        vp[i].resize(a);
        for (int j = 0; j < a; ++j) cin >> vp[i][j].x >> vp[i][j].y;
        p[i] = {mic(vp[i]), i};
    }

    vector<DD> person, ana;
    for (int i = 0; i < p.size(); ++i) person.push_back(p[i].first);
    for (int i = 0; i < r.size(); ++i) ana.push_back(r[i].first);
    if (!can(person, ana)) {
        cout << "NG" << endl;
        return 0;
    }

    for (int i = 0; i < M; ++i) {
        vector<DD> person;
        for (int j = i+1; j < M; ++j) person.push_back(p[j].first);
        for (int j = 0; j < r.size(); ++j) {
            if (p[i].first > r[j].first + EPS) continue;
            vector<DD> ana;
            for (int k = 0; k < r.size(); ++k) {
                if (k == j) continue;
                ana.push_back(r[k].first);
            }
            if (can(person, ana)) {
                cout << r[j].second + 1 << endl;
                r.erase(r.begin()+j);
                break;
            }
        }
    }
}
accuracy: 1
time_ms: 790
memory_kb: 3320
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class d>
struct maxflow{
	struct E{
		int to,rev;
		d cap;
	};
	vvc<E> g;
	vi itr,lv;
	maxflow(int n):g(n),itr(n),lv(n){}
	void ae(int s,int t,d c){
		g[s].pb({t,(int)g[t].size(),c});
		g[t].pb({s,(int)g[s].size()-1,0});
	}
	void bfs(int s){
		fill(all(lv),-1);
		lv[s]=0;
		queue<int> q;
		q.push(s);
		while(q.size()){
			int v=q.front();q.pop();
			for(auto e:g[v])if(e.cap>0&&lv[e.to]==-1){
				lv[e.to]=lv[v]+1;
				q.push(e.to);
			}
		}
	}
	d dfs(int v,int t,d f){
		if(v==t)return f;
		d res=0;
		for(int&i=itr[v];i<(int)g[v].size();i++){
			E& e=g[v][i];
			if(e.cap>0&&lv[e.to]==lv[v]+1){
				d a=dfs(e.to,t,min(f,e.cap));
				if(a>0){
					e.cap-=a;
					g[e.to][e.rev].cap+=a;
					res+=a;
					f-=a;
					if(f<=0)break;
				}
			}
		}
		return res;
	}
	d calc(int s,int t){
		d f=0;
		while(1){
			bfs(s);
			if(lv[t]==-1)
				return f;
			fill(all(itr),0);
			f+=dfs(s,t,1e9);
		}
	}
};

using ld=long double;
using cm=complex<ld>;
#define x real()
#define y imag()
const ld eps=1e-8;
const ld PI=acos(ld(-1));
int sgn(ld a){return a<-eps?-1:(a>eps?1:0);}
ld dot(cm a,cm b){return a.x*b.x+a.y*b.y;}
ld crs(cm a,cm b){return a.x*b.y-a.y*b.x;}
ld crs(cm a,cm b,cm c){return crs(b-a,c-a);}
int ccw(cm a,cm b){return sgn(crs(a,b));}
int ccw(cm a,cm b,cm c){return ccw(b-a,c-a);}

using cr=pair<cm,ld>;
//AOJ2423
cr circumc(cm a,cm b,cm c){
	b-=a;
	c-=a;
	cm r=norm(b)*c-norm(c)*b;
	r=cm(r.y,-r.x)/(2*crs(b,c));
	return cr(a+r,abs(r));
}
//AOJ2423
cr mindisc(const vc<cm>& p,array<cm,3> q,int i,int j){
	if(i==int(p.size())){
		if(j==0)
			return {{0,0},-1};
		else if(j==1)
			return {q[0],0};
		else if(j==2)
			return {(q[0]+q[1])*ld(0.5),abs(q[0]-q[1])/2};
		else if(j==3)
			return circumc(q[0],q[1],q[2]);
		else
			assert(false);
	}
	cr c=mindisc(p,q,i+1,j);
	if(sgn(abs(c.a-p[i])-c.b)==1){
		assert(j<3);
		q[j]=p[i];
		return mindisc(p,q,i+1,j+1);
	}else
		return c;
}
cr mindisc(vc<cm> p){
	shuffle(all(p),mt19937());
	return mindisc(p,array<cm,3>(),0,0);
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	
	int n,m;cin>>n>>m;
	vc<ld> r(n);
	rep(i,n)cin>>r[i];
	vc<ld> p(m);
	rep(i,m){
		int k;cin>>k;
		vc<cm> a;
		rep(j,k){
			ld s,t;
			cin>>s>>t;
			a.eb(s,t);
		}
		p[i]=mindisc(a).b;
	}
	
	int s=1+m+n+1;
	vc<bool> used(n);
	vi ans(m,-1);
	rep(i,m){
		rep(j,n)if(sgn(p[i]-r[j])<=0&&!used[j]){
			used[j]=1;
			maxflow<int> mf(s);
			rng(k,i+1,m){
				mf.ae(0,1+k,1);
				rep(l,n)if(sgn(p[k]-r[l])<=0&&!used[l])
					mf.ae(1+k,1+m+l,1);
			}
			rep(k,n)if(!used[k])
				mf.ae(1+m+k,s-1,1);
			if(mf.calc(0,s-1)==m-1-i){
				ans[i]=j;
				break;
			}
			used[j]=0;
		}
		if(ans[i]==-1){
			cout<<"NG"<<endl;
			return 0;
		}
	}
	for(auto v:ans)
		cout<<v+1<<endl;
}
accuracy: 1
time_ms: 150
memory_kb: 3520
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

namespace MaxFlow{
	using CapType=int;
	struct Edge{
		int to,rev;
		CapType cap;
	};
	vector<vector<Edge>> g;
	vi itr,level;
	void Init(int n){
		g.assign(n,vector<Edge>());
		itr.assign(n,0);
		level.assign(n,0);
	}
	void AddEdge(int from,int to,CapType cap){
		g[from].pb({to,(int)g[to].size(),cap});
		g[to].pb({from,(int)g[from].size()-1,0});
	}
	void bfs(int s){
		fill(level.begin(),level.end(),-1);
		level[s]=0;
		queue<int> q;
		q.push(s);
		while(!q.empty()){
			int v=q.front();q.pop();
			for(auto e:g[v])if(e.cap>0&&level[e.to]==-1){
				level[e.to]=level[v]+1;
				q.push(e.to);
			}
		}
	}
	CapType dfs(int v,int t,CapType f){
		if(v==t)
			return f;
		CapType res=0;
		for(int&i=itr[v];i<(int)g[v].size();i++){
			Edge& e=g[v][i];
			if(e.cap>0&&level[e.to]==level[v]+1){
				CapType d=dfs(e.to,t,min(f,e.cap));
				if(d>0){
					e.cap-=d;
					g[e.to][e.rev].cap+=d;
					res+=d;
					f-=d;
					if(f<=0)break;
				}
			}
		}
		return res;
	}
	CapType Calc(int s,int t){
		CapType flow=0;
		while(1){
			bfs(s);
			if(level[t]==-1)
				return flow;
			fill(itr.begin(),itr.end(),0);
			flow+=dfs(s,t,1e9);
		}
	}
}

using ld=long double;
using cm=complex<ld>;
#define x real()
#define y imag()
const ld eps=1e-8;
const ld PI=acos(ld(-1));
int sgn(ld a){return a<-eps?-1:(a>eps?1:0);}
ld dot(cm a,cm b){return a.x*b.x+a.y*b.y;}
ld crs(cm a,cm b){return a.x*b.y-a.y*b.x;}
ld crs(cm a,cm b,cm c){return crs(b-a,c-a);}
int ccw(cm a,cm b){return sgn(crs(a,b));}
int ccw(cm a,cm b,cm c){return ccw(b-a,c-a);}

using cr=pair<cm,ld>;
cr circumc(cm a,cm b,cm c){
	b-=a;
	c-=a;
	cm r=norm(b)*c-norm(c)*b;
	r=cm(r.y,-r.x)/(2*crs(b,c));
	return cr(a+r,abs(r));
}

cr mindisc(const vc<cm>& p,array<cm,3> q,int i,int j){
	if(i==int(p.size())){
		if(j==0)
			return {{0,0},-1};
		else if(j==1)
			return {q[0],0};
		else if(j==2)
			return {(q[0]+q[1])*ld(0.5),abs(q[0]-q[1])/2};
		else if(j==3)
			return circumc(q[0],q[1],q[2]);
		else
			assert(false);
	}
	cr c=mindisc(p,q,i+1,j);
	if(sgn(abs(c.a-p[i])-c.b)==1){
		assert(j<3);
		q[j]=p[i];
		return mindisc(p,q,i+1,j+1);
	}else
		return c;
}

cr mindisc(vc<cm> p){
	shuffle(all(p),mt19937());
	return mindisc(p,array<cm,3>(),0,0);
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	
	int n,m;cin>>n>>m;
	vc<ld> r(n);
	rep(i,n)cin>>r[i];
	vc<ld> p(m);
	rep(i,m){
		int k;cin>>k;
		vc<cm> a;
		rep(j,k){
			ld s,t;
			cin>>s>>t;
			a.eb(s,t);
		}
		p[i]=mindisc(a).b;
	}
	
	int s=1+m+n+1;
	vc<bool> used(n);
	vi ans(m,-1);
	rep(i,m){
		rep(j,n)if(sgn(p[i]-r[j])<=0&&!used[j]){
			used[j]=1;
			MaxFlow::Init(s);
			rng(k,i+1,m){
				MaxFlow::AddEdge(0,1+k,1);
				rep(l,n)if(sgn(p[k]-r[l])<=0&&!used[l])
					MaxFlow::AddEdge(1+k,1+m+l,1);
			}
			rep(k,n)if(!used[k])
				MaxFlow::AddEdge(1+m+k,s-1,1);
			if(MaxFlow::Calc(0,s-1)==m-1-i){
				ans[i]=j;
				break;
			}
			used[j]=0;
		}
		if(ans[i]==-1){
			cout<<"NG"<<endl;
			return 0;
		}
	}
	for(auto v:ans)
		cout<<v+1<<endl;
}
accuracy: 1
time_ms: 100
memory_kb: 3472
final_rank: 1