麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

Codeforces 732E Sockets【貪心】

2019-11-06 06:32:25
字體:
來源:轉載
供稿:網友

E. Socketstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

Input

The 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.

Output

In 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.

ExamplesInput
2 21 12 2Output
2 21 11 2Input
2 12 10099Output
1 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");    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 密室逃脱第一季免费观看完整在线 | 国产高清成人久久 | 九九热在线视频免费观看 | 久久久电影电视剧免费看 | 在线成人免费视频 | 538任你躁在线精品视频网站 | 免费国产视频在线观看 | 黑人三级毛片 | 国产一有一级毛片视频 | 黄污污网站 | 久久艹国产精品 | 久久久久久久一区二区 | 暖暖免费观看高清完整版电影 | 亚洲精品3| 欧美国产成人在线 | 成人啪啪色婷婷久 | 日本成人在线免费 | 久草在线免费看 | 久色网站| 哪里可以看免费的av | 国产精品成人免费一区久久羞羞 | 久久草在线观看视频 | 毛片在线免费播放 | 中文字幕免费看 | 欧美高清一级片 | 国产精品久久久久久久久久久久久久久 | 免费观看在线 | 黄色av网站免费看 | 国产1区2 | 亚洲精品动漫在线观看 | 中文字幕专区高清在线观看 | 在线看91 | 国产成人精品自拍视频 | 国产91精品一区二区麻豆亚洲 | 国产精品一区二区三区在线看 | 欧美国产第一页 | 国产精品成人av片免费看最爱 | av视在线| 美女在线观看视频一区二区 | 奶子吧naiziba.cc免费午夜片在线观看 | 国产毛片在线 |