原题传送门
贪心,能用小的不用大的
满足
最大的
,一定可以用完
对于
,直接从大到小枚举是否可以看,剩下的给
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;
}