Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int a[100000];
- bool sift_down(int n, int i) {
- int MaxRoot = i;
- int l_child = 2 * i + 1;
- int r_child = 2 * i + 2;
- if (l_child < n && a[l_child] < a[MaxRoot])
- MaxRoot = l_child;
- if (r_child < n && a[r_child] < a[MaxRoot])
- MaxRoot = r_child;
- if (MaxRoot != i)
- return true;
- return false;
- }
- int main()
- {
- ifstream fin("isheap.in");
- ofstream fout("isheap.out");
- int n;
- cin >> n;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- for (int i = n / 2 - 1; i >= 0; i--) {
- if (sift_down(n, i)) {
- cout << "NO" << endl;
- return 0;
- }
- }
- cout << "YES" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement