Advertisement
Josif_tepe

Untitled

Mar 23rd, 2023
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <set>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int n, m;
  11.     cin >> n >> m;
  12.    
  13.     vector<int> rw, rnw, lnw, lw;
  14.     int cnt = 1;
  15.     while(cnt <= 2 * n) {
  16.         lw.push_back(cnt);
  17.         if(cnt + 1 > n * 2) {
  18.             break;
  19.         }
  20.         rw.push_back(cnt + 1);
  21.         cnt += 2;
  22.     }
  23.     while(cnt <= 4 * n) {
  24.         lnw.push_back(cnt);
  25.         if(cnt + 1 > 4 * n) {
  26.             break;
  27.         }
  28.         rnw.push_back(cnt + 1);
  29.         cnt += 2;
  30.     }
  31.     for(int i = 0; i < n; i++) {
  32.         if(lnw[i] <= m and lnw.size() >= i + 1) {
  33.             cout << lnw[i] << " ";
  34.         }
  35.         if(lw[i] <= m and lw.size() >= i + 1) {
  36.             cout << lw[i] << " ";
  37.         }
  38.         if(rnw[i] <= m and rnw.size() >= i + 1) {
  39.             cout << rnw[i] << " ";
  40.         }
  41.         if(rw[i] <= m and rw.size() >= i + 1) {
  42.             cout << rw[i] << " ";
  43.         }
  44.     }
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement