Chaitanya Kolhe thinks that the solution to the problem "test-03 Maximum Subarray Sum" uploaded on GitHub is incorrect. He also provided the following code.
#include<bits/stdc++.h>
#include
#define ll long long
#define pb push_back
using namespace std;
ll solve(int t){
vector arr;
for (int i=0; i<t; i++){
ll temp;
cin >> temp;
arr.pb(temp);
}
if(*max_element(arr.begin(), arr.end()) <= 0){
return *max_element(arr.begin(), arr.end());
}
else{
ll sum=0, max_sum=0;
for (int i=0; i<t; i++){
sum+=arr[i];
max_sum = max(sum, max_sum);
if (sum<0){
sum=0;
}
}
return max_sum;
}
}
int main(){
int t;
cin >> t;
ll ans;
ans = solve(t);
cout << ans << endl;
}
Chaitanya Kolhe thinks that the solution to the problem "test-03 Maximum Subarray Sum" uploaded on GitHub is incorrect. He also provided the following code.
#include<bits/stdc++.h>
#include
#define ll long long
#define pb push_back
using namespace std;
ll solve(int t){
vector arr;
for (int i=0; i<t; i++){
ll temp;
cin >> temp;
arr.pb(temp);
}
}
int main(){
int t;
cin >> t;
ll ans;
ans = solve(t);
cout << ans << endl;
}