#include <map> #include <vector> #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int maxn = 200000 + 5; struct Node { int v, id, num; Node(int v, int id, int num): v(v), id(id), num(num) {} bool operator <(const Node &t) const { return (v < t.v) || (v == t.v && num > t.num); } }; int n, m; int ans[maxn], ans2[maxn]; int total_socket, total_computer; int () { priority_queue<Node> que; map<int, vector<int> > mp; scanf("%d %d", &n, &m); int x; for (int i = 1; i <=n; i++) { scanf("%d", &x); mp[x].push_back(i); } for (int i = 1; i <= m; i++) { scanf("%d", &x); que.push(Node(x, i, 0)); } total_socket = total_computer = 0; while(!que.empty()){ Node tmp = que.top(); que.pop(); if (mp.find(tmp.v) != mp.end() && mp[tmp.v].size()) { ans[tmp.id] = tmp.num; ans2[mp[tmp.v][mp[tmp.v].size()-1]] = tmp.id; total_socket += tmp.num; total_computer ++; mp[tmp.v].pop_back(); } else { if (tmp.v > 1) { que.push(Node(tmp.v - tmp.v/2, tmp.id, tmp.num+1)); } } } printf("%d %dn", total_computer, total_socket); for (int i = 1; i < m; i++) printf("%d ", ans[i]); printf("%dn", ans[m]); for (int i = 1; i < n; i++) printf("%d ", ans2[i]); printf("%dn", ans2[n]); return 0; }
|
近期评论