Educational Codeforces Round 86 (Rated for Div. 2) D Multiple Testcases

考虑按照从大到小的顺序一个一个依次填充下去(平均分配)

ans可以二分,也可以直接求

时间复杂度O(n+K)

#include<bits/stdc++.h>

using namespace std;

#define N 200005

int n, K, i, now, ans, j, x, a[N], c[N], sum[N];
vector<int> b[N];

int main (void)
{
	scanf("%d%d",&n,&K);
	for (i=1; i<=n; i++) scanf("%d",&x),a[x]++; 
	for (i=1; i<=K; i++) scanf("%d",&c[i]);
	for (i=K; i>=1; i--) sum[i]=sum[i+1]+a[i];
	for (i=1; i<=K; i++) ans=max(ans,sum[i]/c[i]+(sum[i]%c[i]>0?1:0));
	printf("%d\n",ans);
	now=0;
	for (i=K; i>=1; i--) for (j=1; j<=a[i]; j++) {
		now=now%ans+1;
		b[now].push_back(i);
	}
	for (i=1; i<=ans; i++) {
		printf("%d ",b[i].size());
		for (j=0; j<b[i].size(); j++) printf("%d ",b[i][j]);
		puts("");
	}
	
	return 0;
}

  然而昨天晚上并没有想出来QAQ wtclQwQ

上一篇:bug 记录 Unable to start ServletWebServerApplicationContext due to multiple ServletWebServerFactory be


下一篇:shiro中多用户的登陆页面(multiple login pages)配置