可以说是超难的一道题了。。。。
全程题解:
https://www.luogu.org/blog/user11765/solution-p1338
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<iostream> #include<algorithm> using namespace std; long long n, m, a[50005]; int main() { cin >> n >> m; long long s = 1, e = n; for (long long i = 1; i <= n; i++) { long long t = (n - i)*(n - i - 1) / 2; if (t >= m)a[s++] = i; else { a[e--] = i; m -= e - s + 1; } } for (int i = 1; i <= n; i++)cout << a[i] << " "; } |