Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int n,a[200001],aux,i;
  4. long long p=0;
  5. void citire()
  6. {
  7. cin>>n;
  8. for(int i=1;i<=n;i++)
  9. cin>>a[i];
  10. }
  11.  
  12. int sortare(int st, int dr)
  13. {
  14. int aux,i,j,di,dj;
  15. di=0;dj=1;i=st;j=dr;
  16. while(i<j)
  17. {
  18. if(a[i]>a[j])
  19. {
  20. aux=a[i];
  21. a[i]=a[j];
  22. a[j]=aux;
  23. aux=di;
  24. di=dj;
  25. dj=aux;
  26. }
  27. i=i+di;
  28. j=j-dj;
  29. }
  30. return i;
  31. }
  32.  
  33. void quick(int st, int dr)
  34. {
  35. int x;
  36. if(st<dr)
  37. {
  38. x=sortare(st,dr);
  39. quick(st,x-1);
  40. quick(x+1,dr);
  41. }
  42. }
  43.  
  44. void rezolva()
  45. {
  46. if(n==1)
  47. p=a[1];
  48. else
  49. { if((long long)a[n]*(long long)a[n-1]>(long long)a[1]*(long long)a[2])
  50. p=(long long)a[n]*(long long)a[n-1];
  51. else
  52. p=(long long)a[1]*(long long)a[2];
  53. }
  54. cout << p;
  55. }
  56. int main()
  57. {
  58. citire();
  59. quick(1,n);
  60. rezolva();
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement