Advertisement
kokokozhina

513

Jan 4th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. void distribution(vector<int> &A, vector<int> &B, vector<int> working, int a, int b)
  9. {
  10.     for(int i = 0; i < a; i++)
  11.         A.push_back(working[i]);
  12.     for(int i = a; i < a + b; i++)
  13.         B.push_back(working[i]);
  14. }
  15.  
  16. void equal(int a)
  17. {
  18.     for(int i = 0; i < a; i++)
  19.         printf("1 ");
  20.     for(int i = 0; i < a; i++)
  21.         printf("2 ");
  22. }
  23.  
  24. int main()
  25. {
  26.     int n, a, b;
  27.     scanf("%d%d%d", &n, &a, &b);
  28.     vector<int> line, working;
  29.     for(int i = 0; i < n; i++)
  30.     {
  31.         int current;
  32.         scanf("%d", &current);
  33.         line.push_back(current);
  34.     }
  35.  
  36.     working = line;
  37.     sort(working.begin(), working.end());
  38.  
  39.     vector<int> A, B;
  40.     if (b > a)
  41.         distribution(B, A, working, b, a);
  42.     if (a > b)
  43.         distribution(A, B, working, a, b);
  44.     if (a == b)
  45.     {
  46.         equal(a);
  47.         return 0;
  48.     }
  49.  
  50.     for(int i = 0; i < n; i++)
  51.     {
  52.         vector<int>::iterator it = A.begin();
  53.         it = find(A.begin(), A.end(), line[i]);
  54.         if (it != A.end())
  55.         {
  56.             printf("1 ");
  57.             A.erase(it);
  58.         }
  59.         else
  60.         {
  61.             it = find(B.begin(), B.end(), line[i]);
  62.             printf("2 ");
  63.             B.erase(it);
  64.         }
  65.     }
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement