Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector<double> scores;
- int main() {
- int R, K;
- cin >> R >> K;
- int N = 1 << R;
- scores.resize(N);
- for (int i = 0; i < N; ++i) cin >> scores[i];
- sort(scores.begin(), scores.end());
- int total = 0;
- for (int n = 1; n < N; n <<= 1) {
- int lowest_index = N - 2 * n;
- for (int i = N - n; i < N; ++i) {
- int score = scores[i];
- auto it = lower_bound(scores.begin(), scores.end(), score - K);
- int j = it - scores.begin();
- lowest_index = max(j, lowest_index);
- if (lowest_index >= N - n) break;
- ++total;
- ++lowest_index;
- }
- }
- cout << total << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment