1 条题解

  • 1
    @ 2025-4-8 13:29:48
    #include <iostream>
    #include <climits>
    using namespace std;
    int main() {
        int n;
        cin >> n;
        int max_sum = INT_MIN; 
        int current_sum = 0;
        bool all_negative = true;
        int max_num = INT_MIN;
        for (int i = 0; i < n; ++i) {
            int num;
            cin >> num;
            if (num >= 0) all_negative = false;
            if (num > max_num) max_num = num;
            current_sum += num;
            if (current_sum > max_sum) {
                max_sum = current_sum;
            }
            if (current_sum < 0) {
                current_sum = 0;
            }
        }
        if (all_negative) {
            max_sum = max_num;
        }
        cout << max_sum << endl;
        return 0;
    }
    • 1

    信息

    ID
    501
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    5
    已通过
    2
    上传者