We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 66f62f9 commit 31afb9fCopy full SHA for 31afb9f
best_approach/max_suarray_sum_without_dp.cpp
@@ -0,0 +1,26 @@
1
+/*
2
+ written by Pankaj Kumar.
3
+ country:-INDIA
4
+*/
5
+#include <bits/stdc++.h>
6
+using namespace std;
7
+typedef vector<int> vi;
8
+#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
9
+/* -----------------------------------------------------------------------------------*/
10
+
11
+int main()
12
+{
13
+ pan;
14
+ int n;
15
+ cin>>n;
16
+ vi v(n,0);
17
+ for(auto &s:v)
18
+ cin>>s;
19
+ int best=0,maxo=0;
20
+ for(int i=0;i<n;i++)
21
+ {
22
+ maxo=max(maxo+v[i],v[i]);
23
+ best=max(best,maxo);
24
+ }
25
+ cout<<"maximum subarray is "<<best<<endl;
26
+}
0 commit comments