#include<iostream> #include<bits/stdc++.h> #define LOCAL //#define DEBUG #define int long long #define MAXN 100020 usingnamespacestd; int n, temp; vector<int> num;//debug 用數列 string q; // istringstream insert ostringstream output //https://stackoverflow.com/questions/3292107/whats-the-difference-between-istringstream-ostringstream-and-stringstream-w stringstream ss;
int32_tmain() { #ifdef LOCAL freopen("in1.txt", "r", stdin); #endif// LOCAL while(getline(cin, q)){ ss.clear(); ss.str(""); ss << q; //將數列字串放入 stringstream num.clear();
int sum=0, max_sum=0; while(1){ ss >> temp; //stringstream.fail() 如果剛剛沒有傳任何資料到變數就是 yes if(ss.fail()) break; num.push_back(temp); //debug 用
sum += temp; //不斷加入數列 i 值 if(sum < 0) sum = 0; //捨棄前面區間 max_sum = max(sum, max_sum); //看看現在區間,與 ans 誰比較大 } cout << max_sum << '\n';