【题解】CF1031C:Cram Time

原题传送门
贪心,能用小的不用大的
满足 i = 1 n i < = a + b \sum_{i=1}^{n}i<=a+b 最大的 i i ,一定可以用完 1 n 1-n
对于 a a ,直接从大到小枚举是否可以看,剩下的给 b b

Code:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL a, b;
int flag[1000010];

int main(){
	scanf("%lld%lld", &a, &b);
	LL x = 1, s = 0;
	while (s + x <= a + b) s += x++;
	--x;
	LL ans = 0, y = x;
	for (LL i = x; i > 0; i = min(a, i - 1))
		if (a >= i) a -= i, flag[i] = 1, ++ans;
	printf("%d\n", ans);
	if (ans > 0){
		for (int i = 1; i <= y; ++i) if (flag[i]) printf("%d ", i);
		puts("");
	}
	printf("%lld\n", y - ans);
	if (y - ans > 0) for (int i = 1; i <= y; ++i) if (!flag[i]) printf("%d ", i);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/ModestCoder_/article/details/108350837
今日推荐