#include #include #include #include #include using namespace std; int main() { ifstream fin("feel.in"); int n; while(fin >> n && n != 0) { vector happiness(n+2); happiness[0] = happiness[n+1] = -1; for(int i = 0; i < n; i++) { fin >> happiness[i+1]; } vector toleft, toright; { vector vHeight, vIndex, vIndex2; for(int i = 0; i < n+2; i++) { int h = happiness[i]; int z = upper_bound(vHeight.begin(), vHeight.end(), h) - vHeight.begin(); vHeight.resize(z); vIndex.resize(z); vIndex2.resize(z); if (vHeight.empty()) { assert(h < 0); toleft.push_back(0); vHeight.push_back(-1); vIndex.push_back(0); vIndex2.push_back(0); } else if (vHeight.back() == h) { toleft.push_back(i - vIndex.back()); vIndex2.back() = i; } else { toleft.push_back(i - vIndex2.back()); vHeight.push_back(h); vIndex.push_back(vIndex2.back()); vIndex2.push_back(i); } /* for(int j = 0; j < (int)vHeight.size(); j++) { cout << "height = " << vHeight[j] << "; index = " << vIndex[j] << endl; } cout << "----" << endl; */ } } { reverse(happiness.begin(), happiness.end()); vector vHeight, vIndex, vIndex2; for(int i = 0; i < n+2; i++) { int h = happiness[i]; int z = upper_bound(vHeight.begin(), vHeight.end(), h) - vHeight.begin(); vHeight.resize(z); vIndex.resize(z); vIndex2.resize(z); if (vHeight.empty()) { assert(h < 0); toright.push_back(0); vHeight.push_back(-1); vIndex.push_back(0); vIndex2.push_back(0); } else if (vHeight.back() == h) { toright.push_back(i - vIndex.back()); vIndex2.back() = i; } else { toright.push_back(i - vIndex2.back()); vHeight.push_back(h); vIndex.push_back(vIndex2.back()); vIndex2.push_back(i); } } reverse(toright.begin(), toright.end()); reverse(happiness.begin(), happiness.end()); } /* for(int i = 0; i < n; i++) { cout << toleft[i+1] << ' '; } cout << endl; for(int i = 0; i < n; i++) { cout << toright[i+1] << ' '; } cout << endl; */ vector hap_sum(n+2); hap_sum[0] = 0; for(int i = 0; i < n; i++) hap_sum[i+1] = hap_sum[i] + happiness[i+1]; /* for(int i = 0; i < n+2; i++) { cout << hap_sum[i] << ' ' << endl; } */ long long int best_happiness = -1; pair range; for(int i = 0; i < n; i++) { int left = (i+1) - toleft[i+1]; int right = (i+1) + toright[i+1]; //cout << i << ": " << left << " - " << right << endl; long long int period_happiness = hap_sum[right-1] - hap_sum[left]; period_happiness *= happiness[i+1]; if (period_happiness > best_happiness) { best_happiness = period_happiness; range = make_pair(left+1, right-1); } } cout << best_happiness << endl << range.first << ' ' << range.second << endl; } return 0; }