another 4 sorting and searching problems

This commit is contained in:
2024-06-04 11:04:33 +02:00
parent 4e39870547
commit 7fd24571df
5 changed files with 106 additions and 1 deletions

View 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;
}