cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

commit e8a9416671aa1aae8b2bfacc6fc0258a4fc17033
parent 25869b2748dada3684846d0b4b82a6335530c5a8
Author: superpozycja <anna@superpozycja.net>
Date:   Sun, 27 Oct 2024 22:58:15 +0100

solve max subarray sum thank you kadane chan

Diffstat:
Asorting_and_searching/max_subarray_sum.cpp | 37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)

diff --git a/sorting_and_searching/max_subarray_sum.cpp b/sorting_and_searching/max_subarray_sum.cpp @@ -0,0 +1,37 @@ +#include <bits/stdc++.h> + +using namespace std; + +using ui = unsigned int; +using l = long; +using ul = unsigned long; +using ll = long long; +using ull = unsigned long long; + +using vi = vector<int>; +using vui = vector<ui>; +using vl = vector<l>; +using vul = vector<ul>; +using vll = vector<ll>; +using vull = vector<ull>; + +void solve() +{ + int n; + cin >> n; + long res = -1000000000, s = -1000000000; + for (int i = 0; i < n; i++) { + long t; + cin >> t; + s = max(s+t, t); + res = max(s, res); + } + cout << res << "\n"; +} + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + solve(); +}