const int N = 6e5 + 5;
int t;
int main()
{ ios::sync_with_stdio(false);cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
int n, p;
while (cin >> n >> p)
{
vector<int> a(N);
f(i, 1, n)cin >> a[i];
sort(a.begin()+1, a.begin()+1+ n);
int l = -2e9, r = 2e9;
f(i, 1, n)l = max(l, a[i] - (i - 1));
f(i, 1, n - p + 1)r = min(r, a[i + p - 1] - (i - 1)-1);
//不能有超过p个位置满足当前的位置,否则组合超过p,必不行
if (l > r)puts("0");
else
{
cout << r - l + 1 << endl;
f(i, l, r)cout << i << " ";
}
}
return 0;
}
E2. Asterism (Hard Version)(思维)
最新推荐文章于 2021-07-04 17:45:13 发布