您的答案為: -2 正確答案為: 0
不太懂 為什麼其他測資都是正確的
只有這個測資錯?
這是我的程式碼
#include <iostream> #include <vector> #include <string> #include <sstream> using namespace std; int main () { int N; while (cin >> N) { vector<int> list; int t; for (int i=0; i<N; i++) { cin >> t; list.push_back(t); } int best = -100; for (int i=1; i<=N; i++) { int sum = 0; auto it = list.begin(); while (it != list.begin()+i) { sum += *it; it++; } if (sum > best) best = sum; while (it != list.end()) { sum += *it; sum -= *(it-i); if (sum > best) best = sum; it++; } } cout << best << endl; } return 0; }