What's the problem in this logic?

#include <iostream>

int main() {
    int t = 0;
    std::cin >> t;
    while (t--) {
        int N = 0, first_non_zero_element_index = 0, flag = 0, curr_sum = 0,
            max_sum = 0;
        std::cin >> N;
        int *arr = new int[N];
        for (int i = 0; i < N; ++i) std::cin >> arr[i];
        for (int i = 0; i < N && flag == 0; ++i) {
            if (arr[i] > 0) {
                first_non_zero_element_index = i;
                flag = 1;
                break;
            }
        }
        for (int i = first_non_zero_element_index; i < N; ++i) {
            curr_sum += arr[i];
            if (curr_sum > max_sum) max_sum = curr_sum;
        }
        std::cout << max_sum << '\n';
    }
}

Hello @moon you have to optimise your approach:
you can do that by using kadanes algorithm.
there must be editorial for this in your course.
you can see that.
if you still you have doubt you can ask here:
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.