Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, k, m, x = 1000, w = 1, t = 0, max = 0 , l;
- cin>>n;
- cin>>k;
- int a[1000];
- int b[1000];
- int c[1000];
- for(int i = 0; i < n; i++)
- {
- a[i] = 0;
- b[i] = 0;
- }
- for(int i = 0;i < n; i++)
- {
- cin>>m;
- if(a[m-1] == 0)
- {
- c[t] = m-1;
- t++;
- }
- a[m-1]++;
- }
- for(int i = 0; i < t; i++)
- {
- if(max < a[с[i]]
- {
- max = a[c[i]];
- }
- }
- for(int i = 0; i < t; i++)
- {
- if(a[c[i]] == max)
- {
- l++;
- }
- }
- if( (max > (n/k) + 1) or ( (max == (n/k) + 1) and (l > n%k) ) )
- {
- cout<<-1;
- }
- else
- {
- for(int i = 0; i < t; i++)
- {
- if(max == (n/k) + 1 and a[c[i]] == max)
- {
- for(int j = 0; j < a[c[i]]; j++)
- {
- b[w] = c[i];
- w += k
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement