another 4 sorting and searching problems
This commit is contained in:
19
CSES - CSES Problem Set/Maximum_Subarray_Sum.cpp
Normal file
19
CSES - CSES Problem Set/Maximum_Subarray_Sum.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Maximum Subarray Sum
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
int n; cin >> n;
|
||||
ll max_sum = INT32_MIN;
|
||||
ll current_sum = INT32_MIN;
|
||||
for (int i{}; i < n; i++) {
|
||||
ll a; cin >> a;
|
||||
current_sum = max(current_sum + a, a);
|
||||
max_sum = max(current_sum, max_sum);
|
||||
}
|
||||
cout << max_sum << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user