fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. const int N = 1e6+7;
  5.  
  6. int a[N];
  7. ll n, k, cnt;
  8.  
  9. int main(){
  10. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  11. cin >> n >> k;
  12. int l = 1, r = n;
  13. for(int i = 1; i <= n; i++){
  14. if(cnt + (n - i) <= k){
  15. cnt += (n - i);
  16. a[r--] = i;
  17. }
  18. else{
  19. a[l++] = i;
  20. }
  21. }
  22. for(int i = 1; i <= n; i++) cout << a[i] << ' ';
  23. return 0;
  24. }
Success #stdin #stdout 0s 4344KB
stdin
7 15
stdout
4 5 6 7 3 2 1