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

why not? 1 test
Posted by Lev_IZR123 16 Dec 2018 22:20
Wrong answer    1 test

#include <iostream>
using namespace std;

int main()
{
    int n, i, x, max;
    int mas[1000];

    cin >> n;
    max = 0;
    for (i = 0; i < n; i++)
    {
        cin >> mas[i];
    }
    max = mas[0] + mas[1] + mas[2];
    x = 1;
    for (i = 1; i < n; i++)
    {
        if (mas[i] + mas[i + 1] + mas[i + 2] > max)
        {
            max = mas[i] + mas[i + 1] + mas[i + 2];
            x = i + 1;
        }
    }
    cout << max << ' ' << x + 1 << endl;
    system("pause");
    return (0);
}
Re: why not? 1 test
Posted by Radu Tache 29 Jan 2019 02:11
Because for i = n - 1, mas[i + 1] and mas[i + 2] go out of bounds
Re: why not? 1 test
Posted by Fyodor 10 Jun 2019 17:23
put the variables above