Codeforces Round 923 (Div. 3) 1927E - Klever Permutation Solution
Problem Link : https://codeforces.com/contest/1927/problem/E
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n , k ; cin >> n >> k ;
- int mn = 1 , mx = n ;
- std::vector<int> ans(n);
- for ( int i = 1 ; i <= k ; i++){
- for ( int j = i ; j <= n ; j += k ){
- if(i % 2 == 1){
- ans[j-1] = mn++ ;
- }
- else{
- ans[j-1] = mx-- ;
- }
- }
- }
- for ( auto i : ans ){
- cout << i <<" ";
- }
- cout <<'\n';
- }
- return 0 ;
- }
No comments