fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. typedef std::pair<int,int> sp;
  6. bool spc(sp one,sp two)
  7. {
  8. return one.first*one.second<two.first*two.second;
  9. }
  10. void check(int &lhs,int &rhs,int cur,int a1,int min)
  11. {
  12. sp tmp1=sp(lhs,rhs);
  13. sp tmp2=sp(lhs,cur);
  14. sp tmp3=sp(a1,cur);
  15. sp tmp4=sp(min,cur);
  16. std::vector<sp> res;
  17. res.push_back(tmp1);res.push_back(tmp2);res.push_back(tmp3);
  18. res.push_back(tmp4);
  19. std::sort(res.begin(),res.end(),spc);
  20. lhs=res[0].first;rhs=res[0].second;
  21. }
  22. int main()
  23. {
  24. int lhs=1000,rhs=1000,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,m=0,cur=0;
  25. int N;
  26. cin>>N;
  27. int i=0;
  28. for(i;i<6;i++)
  29. {
  30.  
  31. a1=a2;
  32. a2=a3;
  33. a3=a4;
  34. a4=a5;
  35. a5=a6;
  36. cin>>cur;
  37. a6=cur;
  38. }
  39. m=a1;
  40. for(i;i<N;i++)
  41. {
  42. cin>>cur;
  43. check(lhs,rhs,cur,a1,m);
  44. m=std::min(m,a1);
  45. a1=a2;
  46. a2=a3;
  47. a3=a4;
  48. a4=a5;
  49. a5=a6;
  50. a6=cur;
  51. }
  52. cout<<endl<<endl;
  53. cout<<lhs*rhs;
  54. return 0;
  55. }
Success #stdin #stdout 0s 3480KB
stdin
11
20
12
11
4
5
9
10
24
43
20
7
stdout

28