E2. Asterism (Hard Version)(思维)
程序员文章站
2022-04-18 11:55:03
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 a(N);f(i, 1, n)cin >> a[i];sort(a.begin()+1, a.begin...
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;
}
本文地址:https://blog.csdn.net/qq_43543086/article/details/107100278