Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created December 21, 2015 12:38
Show Gist options
  • Save henrybear327/d559265b043c519428a7 to your computer and use it in GitHub Desktop.
Save henrybear327/d559265b043c519428a7 to your computer and use it in GitHub Desktop.
AR08.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
int tmp, globalmax = 0, suffixmax = 0;
while (scanf("%d", &tmp) != EOF) {
if (suffixmax + tmp > globalmax) {
suffixmax += tmp;
globalmax = suffixmax;
} else if (suffixmax + tmp >= 0)
suffixmax += tmp;
else
suffixmax = 0;
}
if (suffixmax + tmp > globalmax) {
suffixmax += tmp;
globalmax = suffixmax;
} else if (suffixmax + tmp >= 0)
suffixmax += tmp;
else
suffixmax = 0;
printf("%d\n", globalmax);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment