Advertisement
jeff69

Untitled

Mar 26th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <functional>
  4. #include <algorithm>
  5. #include <math.h>
  6. #include <cmath>
  7. #include <string>
  8. #include <vector>
  9. #include<set>
  10. #include<map>
  11. #include <time.h>
  12. #include <fstream>
  13. using namespace std;
  14. typedef long long ll;
  15.  
  16. typedef double d;
  17. typedef long long ll;
  18.  
  19. int a[10007];
  20.  
  21. int main()
  22. {
  23. /*
  24. freopen("free.in", "r", stdin);
  25.  
  26. freopen("free.out", "w", stdout);
  27. */
  28. //memset(dp, -1, sizeof (dp));
  29. int t;
  30.  
  31. cin >> t;
  32. while (t){
  33. t--;
  34. map <int, int>sum2;
  35. int k; int sum = 0;
  36. int sum22 = 0;
  37. cin >> k;
  38. for (int i = 0; i < k; i++){
  39. cin >> a[i];
  40. if ((i + 1) % 2)sum += a[i];
  41. else{
  42. sum22 += a[i];
  43. sum2[i] = sum22;
  44.  
  45. }
  46. }
  47. int ans = 0;
  48. int test_sum = sum;
  49. if (k % 2){
  50. for (int i = 0; i < k - 1; i++){
  51. if ((i + 1) % 2){
  52. test_sum = test_sum - a[i] + a[i + 1] + sum2[(i + k) % k];
  53. ans = max(ans, test_sum);
  54. }
  55. }
  56.  
  57. }
  58. else ans=max(sum, sum22);
  59. cout << ans;
  60. if (t)cout << endl;
  61.  
  62.  
  63.  
  64.  
  65. }
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement