Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
kadane's algorithm
#include <bits/stdc++.h> using namespace std; int main() { //code int t; cin>>t; while(t--) { int n;cin>>n; vector<int>v(n); for(int i=0;i<n;i++) cin>>v[i]; int overall_best=v[0]; int curr_sum=v[0]; for(int i=1;i<n;i++) { curr_sum=curr_sum+v[i]; if(v[i]>=curr_sum) { curr_sum=v[i]; } overall_best=max(overall_best,curr_sum); } cout<<overall_best<<endl; } return 0; }
run
|
edit
|
history
|
help
0
template
Parser + Str2Int
Hello World - verbose
inversion of array using merge sort
LIS
Palindrome
subset sum=k(dp)
Memory_test
Hii
Test 12(2021)