Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <climits>
- #define _CRT_DISABLE_PERFCRIT_LOCKS
- using namespace std;
- void heap(int arr[], int cur, int end)
- {
- int child = 2 * cur + 1;
- while (child <= end)
- {
- if (child < end && arr[child] > arr[child + 1])
- child++;
- if (arr[cur] > arr[child])
- {
- swap(arr[child], arr[cur]);
- cur = child;
- child = 2 * cur + 1;
- }
- else return;
- }
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- cin.tie(NULL);
- int n, a, k, min;
- ios_base::sync_with_stdio(false);
- cin >> n >> k;
- int arr[100000];
- for (int i = 0; i < k; i++)
- {
- arr[i] = INT_MIN;
- }
- for (int i = 0; i < n; i++)
- {
- ios_base::sync_with_stdio(false);
- cin >> a;
- if (a > arr[0])
- {
- arr[0] = a;
- heap(arr, 0, k - 1);
- }
- }
- ios_base::sync_with_stdio(false);
- cout << arr[0];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement