pdpd123

Problem 7

Feb 17th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. #define endl "\n"
  6.  
  7. using mii = map<int, int>;
  8.  
  9. int main(int argc, const char * argv[]) {
  10.     IOS
  11.  
  12.     int n, k, *a, mx;
  13.     mii m; m.clear();
  14.     cin >> n >> k;
  15.     a = new int[n];
  16.     mx = 0;
  17.     for(int i = 0; i < n; i++) {
  18.         cin >> a[i];
  19.         m[a[i]]++;
  20.         mx = max(mx, m[a[i]]);
  21.     }
  22.     if(mx <= k) {
  23.         cout << "YES\n";
  24.         m.clear();
  25.         mii pt; pt.clear();
  26.         for(int i = 0; i < n; i++) {
  27.             if (i < k) {
  28.                 cout << i+1;
  29.                 pt[i+1] = a[i];
  30.             } else {
  31.                 m[a[i]]++;
  32.                 while (pt[ m[a[i]] ] == a[i])
  33.                     m[a[i]]++;
  34.                 cout << m[a[i]];
  35.             }
  36.             cout << (i==n-1?'\n':' ');
  37.         }
  38.     } else {
  39.         cout << "NO\n";
  40.     }
  41.  
  42.     return 0;
  43. }
Add Comment
Please, Sign In to add comment