Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- int main()
- {
- priority_queue<int, vector<int>, greater<int> >result; //su dung hang doi uu tien de giai
- int a[1000], n;
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- result.push(a[0]);
- result.push(a[1]);
- result.push(a[2]);
- for (int i = 3; i < n; i++) {
- if (a[i] > result.top())
- {
- result.pop();
- result.push(a[i]);
- }
- }
- for (int i = 0; i < 3; i++) {
- cout << result.top() << " ";
- result.pop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement