Skip to content

Commit e0f5762

Browse files
authored
Merge pull request #44 from Golden-Hunter/patch-1
Create Kadanes_Algo
2 parents 826cdbe + 7b13b05 commit e0f5762

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Kadanes_Algo

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int n;
6+
cin >> n;
7+
int ms = 0, cs = 0;
8+
int arr[n];
9+
for (int i = 0; i < n; i++)
10+
{
11+
cin >> arr[i];
12+
cs += arr[i];
13+
if (cs < 0)
14+
cs = 0;
15+
else if (cs >= ms)
16+
ms = cs;
17+
}
18+
cout << ms << endl;
19+
return 0;
20+
}

0 commit comments

Comments
 (0)