携程328笔试t3代码
刚好保存了t3的代码,t4不会
当区间和大于等于0就可以直接抛弃了,因为最小的区间的左区间一定不会大于等于0
#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> nums; long long ans = 0; for (int i = 0; i < n; ++i) { int t; cin >> t; nums.push_back(t); ans += t; } int left = 0, right = 0; long long tsum = 0; long long minum = 0; while (right < n) { if ((nums[right] & 1) == 1 || tsum + nums[right] >= 0) { right++; left = right; tsum = 0; } else { tsum += nums[right]; minum = min(minum, tsum); right++; } //cout << tsum; } cout << ans - (minum / 2); return 0; }