PTA 1007 Maximum Subsequence Sum (25 分)
Posted jawen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PTA 1007 Maximum Subsequence Sum (25 分)相关的知识,希望对你有一定的参考价值。
1 #include <stdio.h> 2 #include <iostream> 3 #include <string.h> 4 #include <vector> 5 #include <algorithm> 6 #include <cassert> 7 #include <queue> 8 using namespace std; 9 int n; 10 int main() 11 12 cin >> n; 13 14 vector<int> vec(n); 15 // for(int i = 0 ;i< n;++i) 16 // 17 // int x; 18 // cin >> x; 19 // vec.push_back(x); 20 // 21 int temp = 0,left = 0,right = n - 1,sum = -1; 22 int tempidx = 0; 23 for(int i = 0;i < n; ++i) 24 25 cin >> vec[i]; 26 temp += vec[i]; 27 if(temp < 0) 28 29 temp = 0; 30 tempidx = i + 1; 31 32 else if(temp > sum) 33 34 sum = temp; 35 right = i; 36 left = tempidx; 37 38 39 if(sum < 0) 40 sum = 0; 41 42 cout << sum << " " << vec[left] << " " << vec[right] << endl; 43
以上是关于PTA 1007 Maximum Subsequence Sum (25 分)的主要内容,如果未能解决你的问题,请参考以下文章
PTA 1007 Maximum Subsequence Sum (25 分)
PTA 1007 Maximum Subsequence Sum