Codeforces1342D - Multiple Testcases(后缀\思维)

Description

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.

题目大意

有n个数字,需要将这些数字分成很多个组,有m个限制,c1,c2,c3,c4…ck 表示每一个组大意等于i的数最多有ci个

求对这些数字求前缀,得到大于等于i的数量suf[i],取max(suf[i]/c[i](向下取整))
这也叫求出组数num
然后就是构造每组
考虑将每一个数字都尽量均匀分布到每一组里
将数字排序,每次取num个数字按顺序放入每一个组…

#include
#define ll long long
using namespace std;
const int maxn=2e5+5;
const int inf=0x3f3f3f3f;
int a[maxn],b[maxn],suf[maxn];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]),++suf[a[i]];
    for(int i=1;i<=m;++i)scanf("%d",&b[i]);
    sort(a+1,a+n+1);
    for(int i=m-1;i>=1;--i)suf[i]+=suf[i+1];
    int ans=0;
    for(int i=1;i<=m;++i){
        int x=(suf[i]+b[i]-1)/b[i];
        ans=max(ans,x);
    }
    printf("%d\n",ans);
    for(int i=1;i<=ans;++i){
        printf("%d",(n-i)/ans+1);
        for(int j=i;j<=n;j+=ans){
            printf(" %d",a[j]);
        }
        putchar('\n');
    }
    return 0;
}

你可能感兴趣的:(Codeforces)