fork(1) download
  1. #include <iostream>
  2. #include <functional>
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <limits.h>
  6. #include <iterator>
  7. #include <assert.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <memory.h>
  11. #include <cstdlib>
  12. #include <cstring>
  13. #include <sstream>
  14. #include <fstream>
  15. #include <stdio.h>
  16. #include <complex>
  17. #include <iomanip>
  18. #include <math.h>
  19. #include <vector>
  20. #include <bitset>
  21. #include <string>
  22. #include <time.h>
  23. #include <ctime>
  24. #include <cmath>
  25. #include <deque>
  26. #include <queue>
  27. #include <map>
  28. #include <set>
  29.  
  30. #define r0 return 0;
  31. #define bn cout << endl;
  32. #define INT long long int
  33. #define vfind(vecName, num) find(vecName.begin(), vecName.end(), num)
  34. #define hmap unordered_map
  35. #define hset unordered_set
  36. #define rnd(n, m) n + rand() % (m+1)
  37. #define resz(a, n) a.resize(n)
  38. #define pb push_back
  39. #define srt(a) sort(a.begin(), a.end())
  40. #define srt2(a) sort(a.begin(), a.end(), [](p a1, p b1)
  41. #define rev(n) reverse(n.begin(), n.end())
  42. #define forn(i, j, n) for (INT i = j; i < n; ++i)
  43. #define forc(i, n) for (int i = n - 1; i >= 0 ; --i)
  44. #define ford(i, j, n) for (INT i = n - 1; i >= j ; --i)
  45. #define foreach(i, a) for (INT i : a)
  46. #define cok cout << "OK" << endl;
  47. #define ARRin(a, n) forn(i, 0, n) cin >> a[i];
  48. #define ARROut(a, c) for (INT i : a) {cout << i << c;}
  49. #define ARROutString(a, sp) for (string i : a) {cout << i << sp;}
  50. #define im int main(int argc, const char * argv[])
  51. #define sync {ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
  52. #define SETout(setName, symb) copy( setName.begin(), setName.end(), ostream_iterator<char>(cout, symb));
  53. #define forSet(setName, type) for (set<type>::iterator i = setName.begin(); i != setName.end(); ++i)
  54. #define dve(type, name, n, m) vector<vector<type> > name(n, vector<type> (m, 0))
  55.  
  56. INT INF = 1e9+337;
  57.  
  58. using namespace std;
  59.  
  60. im {
  61. sync
  62.  
  63. // INT n;
  64. // cin >> n;
  65. // vector<INT> a(n);
  66. // ARRin(a, n);
  67. // srt(a);
  68. // cout << ( ( ( (a[n - 1] * a[n - 2] * a[n - 3]) > (a[0] * a[1] * a[n - 1]) ) ? (a[n - 1] * a[n - 2] * a[n - 3]) : (a[0] * a[1] * a[n - 1]) ) ) << endl;
  69.  
  70. INT n;
  71. cin >> n;
  72.  
  73. int notComplited = 1;
  74.  
  75. INT temp;
  76. INT max1 = -INF, max2 = -INF, max3 = -INF, min1 = INF, min2 = INF;
  77.  
  78. forn(i, 0, n){
  79. cin >> temp;
  80. // if(notComplited == 1){
  81. // notComplited = 0;
  82. // max1 = max2 = max3 = min1 = min2 = temp;
  83. // }
  84. if(temp > max1 && temp > max2 && temp > max3){
  85. max1 = max2;
  86. max2 = max3;
  87. max3 = temp;
  88. }
  89. else if(temp > max1 && temp > max2 && temp < max3){
  90. max1 = max2;
  91. max2 = temp;
  92. }
  93. else if(temp > max1 && temp < max2){
  94. max1 = temp;
  95. }
  96.  
  97. if(temp < min1 && temp < min2){
  98. min1 = min2;
  99. min2 = temp;
  100. }
  101. else if(temp < min1 && temp > min2){
  102. min1 = temp;
  103. }
  104. // cout << min2 << " " << min1 << " " << max1 << " " << max2 << " " << max3 << endl;
  105. }
  106.  
  107. // cout << min2 << " " << min1 << " " << max1 << " " << max2 << " " << max3 << endl;
  108.  
  109. if(max1 * max2 * max3 > min1 * min2 * max3){
  110. cout << max1 << " " << max2 << " " << max3 << endl;
  111. cout << max1 * max2 * max3 << endl;
  112. }
  113. else{
  114. cout << min1 << " " << min2 << " " << max3 << endl;
  115. cout << min1 * min2 * max3 << endl;
  116. }
  117. r0
  118. }
Success #stdin #stdout 0s 4332KB
stdin
5
4
-700
10
-1
5
stdout
-1 -700 10
7000