Advertisement
mxn12

Cau3_3SoLonNhat

Feb 19th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. priority_queue<int, vector<int>, greater<int> >result; //su dung hang doi uu tien de giai
  9. int a[1000], n;
  10. cin >> n;
  11.  
  12. for (int i = 0; i < n; i++) {
  13. cin >> a[i];
  14. }
  15.  
  16. result.push(a[0]);
  17. result.push(a[1]);
  18. result.push(a[2]);
  19.  
  20. for (int i = 3; i < n; i++) {
  21. if (a[i] > result.top())
  22. {
  23. result.pop();
  24. result.push(a[i]);
  25. }
  26. }
  27.  
  28. for (int i = 0; i < 3; i++) {
  29. cout << result.top() << " ";
  30. result.pop();
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement