1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <cstdio> #include <cstring> #include <algorithm> #include <map> #define X first #define Y second
using namespace std;
typedef pair<int, int> pii;
const int maxn = 200010;
int a[maxn], b[maxn]; pii s[maxn]; multimap<int, int> num; multimap<int, int>::iterator it;
int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1, x; i <= n; ++i) { scanf("%d", &x); num.insert(make_pair(x, i)); } for (int i = 1; i <= m; ++i) { scanf("%d", &s[i].X); s[i].Y = i; } sort(s + 1, s + m + 1); int c = 0, u = 0; for (int i = 1; i <= m; ++i) { for (int j = 0; ; ++j) { it = num.find(s[i].X); if (it != num.end()) { a[s[i].Y] = j; b[it -> Y] = s[i].Y; ++c; u += j; num.erase(it); break; } if (s[i].X == 1) { break; } s[i].X -= s[i].X >> 1; } } printf("%d %d\n", c, u); for (int i = 1; i <= m; ++i) { printf("%d ", a[i]); } puts(""); for (int i = 1; i <= n; ++i) { printf("%d ", b[i]); } puts(""); return 0; }
|