Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <bits/stdc++.h>
  6.  
  7. using namespace std;
  8.  
  9. bool sortbysec(const pair<string,int> &a, const pair<string,int> &b)
  10. {
  11.     return (a.second < b.second);
  12. }
  13.  
  14. int main()
  15. {
  16.     int m, w, n, r;
  17.     cin >> m;
  18.     int mw[m];
  19.     for (int i=0; i<m; i++){
  20.         cin >> mw[i];
  21.     }
  22.     cin >> w;
  23.     int ww[w];
  24.     for (int i=0; i<w; i++){
  25.         cin >> ww[i];
  26.     }
  27.     cin >> r >> n;
  28.     pair<string, int> kay[w];
  29.     //memset(kay, 0, w*4);
  30.     for (int i=0; i<w; i++){
  31.         kay[i].second = 0;
  32.         for (int j=0; j<m; j++){
  33.             if (abs(ww[i] - mw[j]) <= r){
  34.                 kay[i].first[j] = '1';
  35.                 kay[i].second++;
  36.             }
  37.             else{
  38.                 kay[i].first[j] = '0';
  39.             }
  40.         }
  41.     }
  42.     sort(kay, kay+n, sortbysec);
  43.     reverse(kay, kay+n);
  44.     for (int i=1; i<w; i++){
  45.         int b = 0;
  46.         if (kay[i-1].second != kay[i].second){
  47.             sort(kay+b, kay+(i-1));
  48.             reverse(kay+b, kay+(i-1));
  49.             b = i;
  50.         }
  51.     }
  52.     for (int i=1; i<w; i++){
  53.         int b = 0;
  54.         if (kay[i-1].first != kay[i].first){
  55.             if ((i-1)-b >= n){
  56.                 cout << endl << kay[i-1].second;
  57.                 return 0;
  58.             }
  59.             b = i;
  60.         }
  61.     }
  62.     cout << endl << -1;
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement