matbensch

TournamentSeedingSolution

Mar 21st, 2022
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. vector<double> scores;
  7.  
  8. int main() {
  9.     int R, K;
  10.     cin >> R >> K;
  11.     int N = 1 << R;
  12.     scores.resize(N);
  13.     for (int i = 0; i < N; ++i) cin >> scores[i];
  14.     sort(scores.begin(), scores.end());
  15.     int total = 0;
  16.     for (int n = 1; n < N; n <<= 1) {
  17.         int lowest_index = N - 2 * n;
  18.         for (int i = N - n; i < N; ++i) {
  19.             int score = scores[i];
  20.             auto it = lower_bound(scores.begin(), scores.end(), score - K);
  21.             int j = it - scores.begin();
  22.             lowest_index = max(j, lowest_index);
  23.             if (lowest_index >= N - n) break;
  24.             ++total;
  25.             ++lowest_index;
  26.         }
  27.     }
  28.     cout << total << endl;
  29.  
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment