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

WA# 6 What is wrong?
Posted by Joe 6 Feb 2015 04:08
#include <stdio.h>


int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    int n;
    scanf("%d", &n);

    long *sections = new long[n];
    for (int i = 0; i < n; i++){
        scanf("%ld", &sections[i]);
    }

    if (n==3){
        printf("%ld %d", sections[0] + sections[1] + sections[2], 2);
    }
    else{
        int i = 0;
        int maxpoint = i;
        while (i + 3 < n){
            int j = i + 1;
            if (sections[i] + sections[i+1] + sections[i+2] < sections[j] + sections[j+1] + sections[j+2]){
                maxpoint = j;
            }
            i++;
        }
        printf("%ld %d", sections[maxpoint] + sections[maxpoint+1] + sections[maxpoint+2], maxpoint+2);
    }

    return 0;
}
Re: WA# 6 What is wrong?
Posted by QLRS 5 Mar 2016 02:00
Input:
5
1 2 3 4 5

Output:
12 4

ENG: Read carefully the terms. Numbers do not necessarily have to be the same. (Google Translate)
RUS: Внимательно читайте условие. Числа не обязательно должны быть одинаковыми.
Re: WA# 6 What is wrong?
Posted by INNOV.Team 21 Apr 2016 18:50
You should not compare sum with the previous sum, but the max sum.
Considering sequence:
1 6 6 6 1 1 1 2 2 2