1006. 求和游戏

Description

石柱上有一排石头键盘,每个键上有一个整数。请你在键盘上选择两个键,使这两个键及其之间的键上的数字和最大。如果这个最大的和不为正,则输出“Game Over"。

Input Format

第1行:键的个数n。

第2..n+1行:键上的数字整数 ai

100ai100

对于70%的数据,2n1,000

对于100%的数据,2n1,000,000

Output Format

一行,最大和或者”Game Over"。

Sample Input

5
3
-5
7
-2
8

Sample Output

13

Sample Input

3
-6
-9
-10

Sample Output

Game Over


#include<iostream>
using namespace std;

int max(int a,int b){
    return a>b ? a : b ;
}

int minn(int a,int b){
    return a>b ? b : a ;
}

int main(){
    int n,x;
    cin>>n;
    int current=0,min=0xffffff,ans=0;
    for(int i=0;i<n;i++){
        cin>>x;
        current+=x;
        ans = max(ans,current-min);
        min = minn(min,current-x);
    }
    if(ans>0){
        cout<<ans;
    }
    else{
        cout<<"Game Over";
    }
    return 0;
} 

 



posted @ 2017-11-03 13:18  bernieloveslife  阅读(292)  评论(0编辑  收藏  举报