deushiro

Untitled

Dec 8th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. using namespace std;
  2.  
  3. int main() {
  4.     ios_base::sync_with_stdio(false);
  5.     cin.tie(0);
  6.     cout.tie(0);
  7.     int n, k;
  8.     cin >> n >> k;
  9.     vector<int> a(n);
  10.     vector<int> ans(n);
  11.     for(int i = 0; i < n; ++i){
  12.         cin >> a[i];
  13.     }
  14.     int x = 0;
  15.     int y = 0;
  16.     int res = k - 1;
  17.     for(int i = 0; i < n; ++i){
  18.  
  19.         if(a[i] == 1){
  20.             ++x;
  21.         }
  22.         else{
  23.             ++y;
  24.         }
  25.         if(min(x, y) + (k - i - 1) < n || max(x, y) == n){
  26.             res = i;
  27.             break;
  28.         }
  29.     }
  30.     cout << res + 1;
  31.     cout << endl;
  32.     for(int i = 0; i <= min(k - 1 ,res); ++i){
  33.         cout << 0 << " ";
  34.     }
  35.     for(int i = res + 1; i < k; ++i){
  36.         cout << 1 << " ";
  37.     }
  38.     cout << endl;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment