fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long t,n;
  4. const int Nmax=100000+5;
  5. long long a[Nmax];
  6.  
  7. long long ans(int i){
  8. if(i>=n)
  9. return 0;
  10. long long x,y,z;
  11. if(i<n)
  12. x=a[i]+ans(i+2);
  13. if(i+1<n)
  14. y=a[i]+a[i+1]+ans(i+4);
  15. if(i+2<n)
  16. z=a[i]+a[i+1]+a[i+2]+ans(i+6);
  17. return max(x,max(y,z));
  18. }
  19.  
  20. int main(){
  21. cin>>t;
  22. while(t--){
  23. cin>>n;
  24. for(int i=0;i<n;i++)
  25. cin>>a[i];
  26. cout<<ans(0)<<endl;
  27. }
  28. }
Success #stdin #stdout 0s 4252KB
stdin
Standard input is empty
stdout
Standard output is empty