Advertisement
nicuvlad76

Untitled

Dec 10th, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <algorithm>
  4. # define N 100005
  5. using namespace std;
  6. ifstream fin(".in");
  7. ofstream fout(".out");
  8. /// metoda greedy = lacom
  9. /**
  10. var 1: calc min1, min2 si max1 max 2 si camparam cele 2 produse
  11. var 2: sortam vector cresc se compara prod primelor 2 valori si a ultimelor 2 valori
  12. */
  13.  
  14. int n, a[N];
  15. ///var 2
  16. void Citire()
  17. {
  18. cin>>n;
  19. for(int i=1;i<=n;i++)
  20. cin>>a[i];
  21. }
  22. void Greedy()
  23. {
  24. sort(a+1, a+n+1);///STL
  25. cout<<max(a[1]*a[2], a[n]*a[n-1]);
  26. }
  27.  
  28. int main()
  29. {
  30. Citire();
  31. Greedy();
  32. return 0;
  33. }
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement