#include <iostream>
int main() {
int N = 0, t = 0, curr_sum = 0, max_sum = 0, A[20] = {0},
maxSum[100000] = {0};
std::cin >> N;
for (int i = 0; i < N; ++i) {
std::cin >> t;
for (int j = 0; j < t; ++j) {
std::cin >> A[j];
curr_sum += A[j];
if (curr_sum < 0) curr_sum = 0;
max_sum = std::max(max_sum, curr_sum);
}
maxSum[i] = max_sum;
}
for (int i = 0; i < N; ++i) std::cout << maxSum[i] << '\n';
return 0;
}
Please, tell me why is it still wrong?
Hello @moon i have given you the correct code:
i think you should need explanation of the logic.
could you please share your logic so that we can discuss what is the problem in your code:
Happy Learning!!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.