标签:ffffff XML 选择 turn font return space script 1.5
石柱上有一排石头键盘,每个键上有一个整数。请你在键盘上选择两个键,使这两个键及其之间的键上的数字和最大。如果这个最大的和不为正,则输出“Game Over"。
第1行:键的个数n。
第2..n+1行:键上的数字整数 ai
。
?100≤ai≤100
对于70%的数据,2≤n≤1,000
对于100%的数据,2≤n≤1,000,000
一行,最大和或者”Game Over"。
5
3
-5
7
-2
8
13
3
-6
-9
-10
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;
}
标签:ffffff XML 选择 turn font return space script 1.5
原文地址:http://www.cnblogs.com/bernieloveslife/p/7777740.html