当前位置: 移动技术网 > 移动技术>移动开发>IOS > E2. Asterism (Hard Version)(思维)

E2. Asterism (Hard Version)(思维)

2020年07月08日  | 移动技术网移动技术  | 我要评论
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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网