URAL 1910 Titan Ruins: Hidden Entrance (阅读理解)

1910. Titan Ruins: Hidden Entrance

Time limit: 1.0 second
Memory limit: 64 MB
Soren and Alba were famous and powerful wizards. They had been the founders of a magic guild that had united wizards of the Northern Territories and given them freedom and independence from the Southern Empire. Despite their venerable age, the friends still took an active part in all important events. When explorers of the Aspen Gorges found the remains of structures built by ancient Titans, who had created the world, Soren and Alba were among the first wizards to arrive to the place. They knew that Titans had been the most powerful wizards ever, and almost any study of their traces would give a strong impulse to the development of modern magic and would allow to understand the nature of magic on the whole.
When Soren and Alba approached the Titan Ruins, they saw a blank wall standing out only a little bit against a rock. The wall was divided into small identical sections.
`Where's the entrance?' Soren asked.
`It's hidden, I suppose,' Alba said. `Did you think that Titans would open the gate for you? They were always very serious about their safety. But I'm sure there's a real door somewhere among these sections. As far as I remember, all Titans' structures that we know have a door, and its width is exactly three such sections.'
`That's good, but how can we find it? The wall is long, and the spell for dispersing such illusions requires much magic power. We can't apply the spell to the whole wall.'
`Yes, the Masking Spell affects the whole wall, but its force is nonuniform. I'm almost sure the spell is strongest exactly where the door is hidden. I have just activated the Magic Field Scanning Spell, and very soon we'll know the force of the field acting on each section. We'll only have to choose three consecutive sections with maximum total force of the field and apply the Dispersal Spell to these sections.'

Input

The first line contains the number  n of sections in the wall (3 ≤  n ≤ 1000). In the second line you are given  n positive integers  a i, which are the forces of the magic field acting on each section (1 ≤  a i ≤ 10 6).

Output

Output two integers separated with a space. They should be the maximum total force of the field acting on three consecutive sections of the wall and the number of the middle section in this segment. It is guaranteed that there is only one answer.

Sample

input output
6
1 4 4 4 1 1
12 3




题意:给一个序列,找出其中连续和最大的3个数,输出3个数的最大连续和 及 这3个数字的中间数字的位置。

解析:直接扫一遍枚举序列的起点位置即可。



AC代码:

#include <cstdio>
#include <algorithm>
using namespace std;

int a[1002];

int main(){
    int n;
    while(scanf("%d", &n)==1){
        for(int i=0; i<n; i++) scanf("%d", &a[i]);
        int maxsum = 0,sum = 0, i = 0;
        for(int k=0; k<n-2; k++){               //枚举序列的起点
            sum = a[k] + a[k+1] + a[k+2];
            if(sum > maxsum){
                maxsum = sum;
                i = k;
            }
        }
        printf("%d %d\n", maxsum, i + 2);       //下标从0开始的,故i+2
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值