Codeforces Round 923 (Div. 3) 1927E - Klever Permutation Solution


 

Problem Link :  https://codeforces.com/contest/1927/problem/E

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n , k ; cin >> n >> k ;
  11. int mn = 1 , mx = n ;
  12. std::vector<int> ans(n);
  13. for ( int i = 1 ; i <= k ; i++){
  14. for ( int j = i ; j <= n ; j += k ){
  15. if(i % 2 == 1){
  16. ans[j-1] = mn++ ;
  17. }
  18. else{
  19. ans[j-1] = mx-- ;
  20. }
  21. }
  22. }
  23. for ( auto i : ans ){
  24. cout << i <<" ";
  25. }
  26. cout <<'\n';
  27. }
  28. return 0 ;
  29. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.