Guest User

Untitled

a guest
Jan 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. //d784. 連續元素的和 by Snail
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main () {
  7. int tc, n, s, a, maxs;
  8. cin >> tc;
  9. while (tc--) {
  10. cin >> n >> s; //輸入第一個數字
  11. maxs = -1000000;
  12. while (--n) { //輸入剩下的n-1個數字
  13. cin >> a;
  14. s = max (a, a+s); //當前最大和
  15. maxs = max (s, maxs); //全域最大和
  16. }
  17. cout << maxs << endl;
  18. }
  19. }
Add Comment
Please, Sign In to add comment