fork download
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int find_max_vapor_rate(vector<int>& vapor_rates) {
  9. int n = vapor_rates.size();
  10. if (n % 2 != 0) {
  11. return 0; // If the number of chemicals is odd, there's no way to pair them up.
  12. }
  13.  
  14. // Divide the chemicals into two sets and reverse the order of one set
  15. vector<int> set1(vapor_rates.begin(), vapor_rates.begin() + n / 2);
  16. vector<int> set2(vapor_rates.begin() + n / 2, vapor_rates.end());
  17. reverse(set2.begin(), set2.end());
  18.  
  19. // Calculate the vapor rates for all possible pairings
  20. vector<int> vapor_products(n / 2);
  21. for (int i = 0; i < n / 2; ++i) {
  22. vapor_products[i] = set1[i] * set2[i];
  23. }
  24.  
  25. // Find the maximum vapor rate
  26. int max_vapor_rate = *max_element(vapor_products.begin(), vapor_products.end());
  27. return max_vapor_rate >= 0 ? max_vapor_rate : 0;
  28. }
  29.  
  30. int main() {
  31. int num_chemicals;
  32. cin >> num_chemicals;
  33.  
  34. vector<int> vapor_rates(num_chemicals);
  35. for (int i = 0; i < num_chemicals; ++i) {
  36. cin >> vapor_rates[i];
  37. }
  38.  
  39. int max_vapor_rate = find_max_vapor_rate(vapor_rates);
  40. cout << max_vapor_rate << endl;
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0