Created
May 18, 2015 02:50
-
-
Save luccasiau/657c89a7f0ca97256bc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// pizza.cpp | |
// programas2 | |
// | |
// Created by Lucca Siaudzionis on 03/01/13. | |
// Copyright (c) 2013 Luccasiau. All rights reserved. | |
// | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#define max(A,B) (A)>(B)?(A):(B) | |
#define MAXN 200010 | |
int main(){ | |
int n; | |
int myv[MAXN]; | |
memset(myv,0,sizeof myv); | |
scanf("%d",&n); | |
for(int i = 1;i<=n;i++){ | |
scanf("%d",&myv[i]); | |
myv[n+i] = myv[i]; | |
} | |
int cont = 0; | |
int soma = 0; | |
int resp = 0; | |
for(int i = 1;i<=2*n;i++){ | |
soma += myv[i]; | |
resp = max(resp,soma); | |
cont++; | |
//printf("(%d %d)\n",soma,resp); | |
if(soma < 0){ | |
soma = 0; | |
cont = 0; | |
//printf("[%d]\n",i); | |
} | |
if(cont == n){ | |
cont = 0; | |
soma = 0; | |
i = i-n+2; | |
} | |
} | |
printf("%d\n",resp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment