The ICM ACPC World Finals is coming! Unfortunately, the organizers of the competition were so busy PReparing tasks that totally missed an important technical point — the organization of electricity supplement for all the participants workstations.
There are n computers for participants, thei-th of which has power equal to positive integerpi. At the same time there arem sockets available, the j-th of which has power euqal to positive integer sj. It is possible to connect thei-th computer to the j-th socket if and only if their powers are the same: pi = sj. It is allowed to connect no more than one computer to one socket. Thus, if the powers of all computers and sockets are distinct, then no computer can be connected to any of the sockets.
In order to fix the situation professor Puch Williams urgently ordered a wagon of adapters — power splitters. Each adapter has one plug and one socket with a voltage divider between them. After plugging an adapter to a socket with powerx, the power on the adapter's socket becomes equal to, it means that it is equal to the socket's power divided by two with rounding up, for example and.
Each adapter can be used only once. It is possible to connect several adapters in a chain plugging the first to a socket. For example, if two adapters are plugged one after enother to a socket with power10, it becomes possible to connect one computer with power3 to this socket.
The organizers should install adapters so that it will be possible to supply with electricity the maximum number of computersc at the same time. If there are several possible connection configurations, they want to find the one that uses the minimum number of adaptersu to connect c computers.
Help organizers calculate the maximum number of connected computers c and the minimum number of adapters u needed for this.
The wagon of adapters contains enough of them to do the task. It is guaranteed that it's possible to connect at least one computer.
InputThe first line contains two integers n andm (1 ≤ n, m ≤ 200 000) — the number of computers and the number of sockets.
The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 109) — the powers of the computers.
The third line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 109) — the power of the sockets.
OutputIn the first line print two numbers c andu — the maximum number of computers which can at the same time be connected to electricity and the minimum number of adapters needed to connectc computers.
In the second line print m integers a1, a2, ..., am (0 ≤ ai ≤ 109), where ai equals the number of adapters orginizers need to plug into thei-th socket. The sum of all ai should be equal to u.
In third line print n integers b1, b2, ..., bn (0 ≤ bi ≤ m), where the bj-th equals the number of the socket which thej-th computer should be connected to. bj = 0 means that the j-th computer should not be connected to any socket. All bj that are different from0 should be distinct. The power of the j-th computer should be equal to the power of the socket bj after plugging in abj adapters. The number of non-zerobj should be equal toc.
If there are multiple answers, print any of them.
ExamplesInput2 21 12 2Output2 21 11 2Input2 12 10099Output1 661 0题目大意:
一共有N个插座,有M台电脑,一台电脑和插座可以相连的要求是:pi==si.现在希望尽可能多的电脑能够连在插排上。
现在有一种分流插座,可以使得一台电脑的si从si变成【si/2】【15/2】=8.
对于一台电脑,我们也可以使用多个分流插座。
问最多能够有几台电脑连在插排上,同时问需要多少个分流插座。
第二行输出每个电脑用的分流插座的数量。
第三行输出每个插排连接的电脑编号。
思路:
首先我们将插排和电脑按照值从小到大排序。
然后我们暴力处理,将每个电脑不断的/2.如果遇到了一个插排可以与之匹配,那么直接相连接即可。
常数大的话是会TLE的,做好底层优化,剩下的vector和map乱搞乱存就行。
Ac代码:
#include<stdio.h>#include<string.h>#include<algorithm>#include<vector>#include<map>using namespace std;#define ll __int64struct node{ ll pos,val;}b[200050],a[200050];vector<ll >mp[200050];ll from[200050];ll use[200050];ll ned[200050];ll ans[200050];ll cmp(node a,node b){ return a.val<b.val;}int main(){ ll n,m; while(~scanf("%I64d%I64d",&n,&m)) { map<ll ,ll >s; memset(from,0,sizeof(from)); memset(use,0,sizeof(use)); memset(ans,-1,sizeof(ans)); for(int i=0;i<=n+m;i++)mp[i].clear(); for(ll i=0;i<n;i++)scanf("%I64d",&a[i].val),a[i].pos=i; for(ll i=0;i<m;i++)scanf("%I64d",&b[i].val),b[i].pos=i; sort(a,a+n,cmp); sort(b,b+m,cmp); int cnt=1; for(int i=0;i<n;i++) { if(s[a[i].val]==0) { s[a[i].val]=cnt; cnt++; } mp[s[a[i].val]].push_back(a[i].pos); } int num=0,tot=0; for(int i=0;i<m;i++) { int contz=0; while(b[i].val) { int ok=0; if(s[b[i].val]!=0) { for(int j=from[s[b[i].val]];j<mp[s[b[i].val]].size();j++) { int v=mp[s[b[i].val]][j]; if(ans[v]==-1) { from[s[b[i].val]]=j+1; ok=1; num++; tot+=contz; ned[b[i].pos]=contz; ans[v]=b[i].pos; break; } } } if(ok==1)break; if(b[i].val==1)break; if(b[i].val%2==1)b[i].val++; b[i].val/=2; contz++; } } printf("%d %d/n",num,tot); for(int i=0;i<m;i++) { printf("%d ",ned[i]); } printf("/n"); for(int i=0;i<n;i++) { printf("%d ",ans[i]+1); } printf("/n"); }}
新闻热点
疑难解答