ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1910. Titan Ruins: Hidden Entrance

C++ 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