【題解】ZeroJudge b565: 5.採蘑菇攻略問題

題目敘述:https://zerojudge.tw/ShowProblem?problemid=b565

#include <iostream>
using namespace std;

int main(){
    int n, temp, total, maxi;
    while (cin >> n){
        maxi = 0;
        total = 0;
        for (int i = 0; i < n; i++){
            cin >> temp;
            total += temp;
            maxi = max(maxi, total);
            if (total < 0) total = 0;
        }
        cout << maxi << "\n";
    }
}
分享本文 Share with friends