Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
max subsequence of array
#include <stdio.h> int main(void) { int arr[] = {-11,-2,3,-1,2,-9,-4,-5,-2, -3}; int cur = arr[0] >= 0? arr[0] : 0, max = arr[0]; int start = 0, end = 0; int i,j = cur == 0 ? 1 : 0; printf("Cur\tMax\tStart\tEnd\n"); printf("%d\t%d\t%d\t%d\n",cur,max,start,end); for (i = 1; i < 10; i++) { cur += arr[i]; if (cur > max) { max = cur; end = i; if (j > start) start = j; } if (cur < 0) { cur = 0; j = i+1; } printf("%d\t%d\t%d\t%d\n",cur,max,start,end); } }
run
|
edit
|
history
|
help
0
Wave Sort
1568-1644 Solar eclipses, make 1617(8) and 1620(12) Lunar eclipses the same as Chinese records
Even Odd using Functions
append
DP on Trees: Type B (In/out Dp)
static property
Breakfast Static Function
‘int R::print() const’ cannot be overloaded
Sieve Of Eratosthenes
CodeChef P1 MATMIN1