fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. /* n - size of array
  6.  * arr - array
  7.  */
  8. int main() {
  9. int Product = 1, maxProduct = INT_MIN, Idx = 0;
  10. int resi, resj;
  11.  
  12. vector<int> arr = {};
  13. int n = arr.size();
  14.  
  15. for (int i=0; i<n; i++) {
  16. if (arr[i]==0) {
  17. Idx = i+1;
  18. Product = 1;
  19. } else {
  20. Product *= arr[i];
  21. if (Product > maxProduct) {
  22. resi = Idx;
  23. resj = i;
  24. maxProduct = Product;
  25. }
  26. }
  27. }
  28. Product = 1;
  29. Idx = n-1;
  30. for (int i=n-1; i>=0; i--) {
  31. if (arr[i]==0) {
  32. Idx = i-1;
  33. Product = 1;
  34. } else {
  35. Product *= arr[i];
  36. if (Product > maxProduct) {
  37. resi = i;
  38. resj = Idx;
  39. maxProduct = Product;
  40. }
  41. }
  42. }
  43. if (maxProduct==INT_MIN) {
  44. if (n>0)
  45. cout << "0," << n-1 << endl;
  46. else
  47. cout << "-1,-1" << endl;
  48. } else {
  49. cout << resi << "," << resj << endl;
  50. }
  51.  
  52. // your code goes here
  53. return 0;
  54. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
-1,-1