D. Multiple Testcases(贪心,二分)

vector<int> v[N];
int a[N], c[N],cnt;
bool check(int mid,int i)
{
	if (v[mid].size() < i)return true;
	return false;
}
int main() 
{
	int n, k;
	cin >> n >> k;
	f(i, 1, n)scanf("%d", &a[i]);
	f(i, 1, k)scanf("%d", &c[i]);
	sort(a + 1, a + 1 + n);
	int lastpos = n;
	ff(i, k, 1)
	{
		int pos = lower_bound(a + 1, a + 1 + n, i) - a;//>=i
		int l = 1, r = cnt;
		int pos2 = 0;
		while (l <= r)//get first pos of size()
		{
			int mid = (l + r) / 2;
			if (check(mid,c[i]))
			{
				pos2 = mid;
				r = mid - 1;
			}
			else l = mid + 1;
		}if (pos2 == 0&&pos<=lastpos)pos2 = ++cnt;
		//debug(pos), debug(pos2);
		f(j, pos, lastpos)
		{
			if (v[pos2].size() >= c[i])
			{
				pos2++;
				if (pos2 > cnt)cnt++;//new
			}
			v[pos2].push_back(a[j]);
		}
		lastpos = pos-1;
	}
	cout << cnt << endl;
	f(i, 1, cnt)
	{
		cout << v[i].size() << " ";
		for (auto I : v[i])
		{
			printf("%d ", I);
		}
		printf("\n");
	}
	return 0;
}

你可能感兴趣的:(Codeforces,pupil)