Skip to content

Instantly share code, notes, and snippets.

@luccasiau
Created May 18, 2015 02:50
Show Gist options
  • Save luccasiau/657c89a7f0ca97256bc4 to your computer and use it in GitHub Desktop.
Save luccasiau/657c89a7f0ca97256bc4 to your computer and use it in GitHub Desktop.
//
// 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