(贪心+优先队列)Educational Codeforces Round 86 (Rated for Div. 2) D. Multiple Testcases

48 篇文章 0 订阅

题意:n个物体,每个物体重量ai,ci代表背包能装重量>=i的物体ci个,问最少要几个背包才能装完,并输出每个背包装了哪些物体

思路:首先二分出最小背包数,然后从后往前遍历,重量为i的物体你要把它装到背包时,挑装的最少的背包装就好了

output

standard output

So you decided to hold a contest on Codeforces. You prepared the problems: statements, solutions, checkers, validators, tests... Suddenly, your coordinator asks you to change all your tests to multiple testcases in the easiest problem!

Initially, each test in that problem is just an array. The maximum size of an array is k

. For simplicity, the contents of arrays don't matter. You have n tests — the i-th test is an array of size mi (1≤mi≤k

).

Your coordinator asks you to distribute all of your arrays into multiple testcases. Each testcase can include multiple arrays. However, each testcase should include no more than c1

arrays of size greater than or equal to 1 (≥1), no more than c2 arrays of size greater than or equal to 2, …, no more than ck arrays of size greater than or equal to k. Also, c1≥c2≥⋯≥ck

.

So now your goal is to create the new testcases in such a way that:

  • each of the initial arrays appears in exactly one testcase;
  • for each testcase the given conditions hold;
  • the number of testcases is minimum possible.

Print the minimum possible number of testcases you can achieve and the sizes of arrays included in each testcase.

Input

The first line contains two integers n

and k (1≤n,k≤2⋅105

) — the number of initial tests and the limit for the size of each array.

The second line contains n

integers m1,m2,…,mn (1≤mi≤k

) — the sizes of the arrays in the original tests.

The third line contains k

integers c1,c2,…,ck (n≥c1≥c2≥⋯≥ck≥1); ci is the maximum number of arrays of size greater than or equal to i

you can have in a single testcase.

Output

In the first line print a single integer ans

(1≤ans≤n

) — the minimum number of testcases you can achieve.

Each of the next ans

lines should contain the description of a testcase in the following format:

t

a1 a2 … at (1≤t≤n) — the testcase includes t arrays, ai is the size of the i

-th array in that testcase.

Each of the initial arrays should appear in exactly one testcase. In particular, it implies that the sum of t

over all ans testcases should be equal to n

.

Note that the answer always exists due to ck≥1

(and therefore c1≥1

).

If there are multiple answers, you can output any one of them.

Examples

Input

Copy

4 3
1 2 2 3
4 1 1

Output

Copy

3
1 2
2 1 3
1 2

Input

Copy

6 10
5 8 1 10 8 7
6 6 4 4 3 2 2 2 1 1

Output

Copy

2
3 8 5 7
3 10 8 1

Input

Copy

5 1
1 1 1 1 1
5

Output

Copy

1
5 1 1 1 1 1

Input

Copy

5 1
1 1 1 1 1
1

Output

Copy

5
1 1
1 1
1 1
1 1
1 1

Note

In the first example there is no way to distribute the tests into less than 3

testcases. The given answer satisfies the conditions: each of the testcases includes no more than 4 arrays of size greater than or equal to 1 and no more than 1 array of sizes greater than or equal to 2 and 3

.

Note that there are multiple valid answers for this test. For example, testcases with sizes [[2],[1,2],[3]]

would also be correct.

However, testcases with sizes [[1,2],[2,3]]

would be incorrect because there are 2 arrays of size greater than or equal to 2

in the second testcase.

Note the difference between the third and the fourth examples. You can include up to 5

arrays of size greater than or equal to 1 in the third example, so you can put all arrays into a single testcase. And you can have only up to 1 array in the fourth example. Thus, every array should be included in a separate testcase.

#include<stdio.h>
#include<string.h>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<math.h>
#include<set>
#include<algorithm>
#include<string>
#include<queue>
#define ll long long
using namespace std;
#define maxn 322220
#include<iostream>
vector<ll>ans[maxn];
ll a[maxn],c[maxn],b[maxn];ll n,k;

struct node
{
    ll id;
    friend bool operator < (node n1, node n2)
    {
        return ans[n1.id].size()>ans[n2.id].size();//自定义优先级从大到小
    }
};
priority_queue<node>que;
//multiset<node>que;
ll pd(ll mid)
{
    ll x=0,y=0;
    for(ll i=k;i>=1;i--)
    {
        if(a[i]>mid*c[i]-y) return 0;
        y+=a[i];
    }
    return 1;
}
int main()
{

    scanf("%lld %lld",&n,&k);
    for(ll i=1;i<=n;i++)
    {
        ll x;
        scanf("%lld",&x);
        a[x]++;
    }
    for(ll i=1;i<=k;i++) scanf("%lld",&c[i]);
    ll l=1,r=n,p=0;
    while(l<=r)
    {
        ll mid=(l+r)/2ll;
        if(pd(mid)==1)
        {
            p=mid;
            r=mid-1;
        }
        else l=mid+1;
    }

    for(ll i=1;i<=p;i++)
    {
        //vector<ll>num;
        //num.clear();
        //printf(">>>\n");
        que.push({i});
    }
    for(ll i=k;i>=1;i--)
    {
        //x+=c[i];
        for(ll j=1;j<=a[i];j++)
        {
            ll x=que.top().id;
            que.pop();
            ans[x].push_back(i);
            //printf("i=%lld j=%lld x=%lld size=%lld\n",i,j,x,(ll)ans[x].size());
            que.push({x});
            //printf("---\n");
            /*vector<ll>num;
            num.insert(num.end(), que.top().num.begin(), que.top().num.end());
            //num=que.top().num;
            que.pop();
            num.push_back(i);
            que.push({num});*/
            //que.top().num.push_back(i);
            //set<node>::iterator it=que.begin();
            //it->num.push_back(i);
        }
    }
    printf("%d\n",p);
    for(ll i=1;i<=p;i++)
    {
        //num.clear();
        //que.top().num;
        //printf("%d ",que.top().num.size());
        printf("%d ",ans[i].size());
        for(ll j=0;j<ans[i].size();j++)
        {
            printf("%d",ans[i][j]);
            if(j==ans[i].size()-1) printf("\n");
            else printf(" ");
        }que.pop();
    }
}

 

"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值