|
|
back to boardC++ Why don't working WA #6 Posted by dimfay 30 Oct 2019 20:58 #include <iostream> #include <math.h> #include <iomanip> #include <vector> #include <map> #include <string> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> vec; for (int i = 0; i < n; i++) { int num; cin >> num; vec.push_back(num); } int max = 0; int sum = 0, seredina = 0; int index = 0; multimap<int, int> index_sum; for (int i = 2; i < vec.size(); i++) { sum = 0; if (vec[i] >= vec[i - 1] && vec[i - 1] >= vec[i - 2]) { sum += vec[i] + vec[i-1] + vec[i-2]; index_sum.insert(pair<int, int>(i, sum)); } } for (auto it = index_sum.begin(); it != index_sum.end(); it++) { if (it->second > max) { max = it->second; sum = max; seredina = it->first; } } cout << sum << " " << seredina; return 0; } Edited by author 30.10.2019 21:02 |
|
|