Skip to content

Commit

Permalink
Kandane's algorithum
Browse files Browse the repository at this point in the history
  • Loading branch information
AdithyakrishnaV committed Sep 23, 2021
1 parent d509fe1 commit 2846c38
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions Kandane's_algorithum.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@

//Kandane's algorithum

// #include <bits/stdc++.h>
// using namespace std;
#include <bits/stdc++.h>
using namespace std;

// int main(){
// int n;
// cin>>n;
int main(){
int n;
cin>>n;

// int a[n];
int a[n];

// for(int i=0; i<n; i++){
// cin>>a[i];
// }
for(int i=0; i<n; i++){
cin>>a[i];
}

// int max_sum = INT_MIN, current_sum=0;
int max_sum = INT_MIN, current_sum=0;

// for(int i=0; i<n; i++){
for(int i=0; i<n; i++){

// current_sum = current_sum+a[i];
current_sum = current_sum+a[i];

// if(current_sum > max_sum){
// max_sum = current_sum;
// }
// if(current_sum < 0){
// current_sum = 0;
// }
if(current_sum > max_sum){
max_sum = current_sum;
}
if(current_sum < 0){
current_sum = 0;
}

// }
}

// cout<<max_sum<<endl;
cout<<max_sum<<endl;

// return 0;
// }
return 0;
}

0 comments on commit 2846c38

Please sign in to comment.