fork download
  1. /* package codechef; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.io.BufferedReader;
  7. import java.io.FileReader;
  8. import java.io.IOException;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Codechef
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. int t = Integer.parseInt(br.readLine());
  16. while(t>0){
  17. String b = br.readLine();
  18. String b1[] = b.split(" ");
  19. int n=Integer.parseInt(b1[0]);
  20. int k=Integer.parseInt(b1[1]);
  21. String a = br.readLine();
  22. String a1[] = a.split(" ");
  23. int g[] = new int[n];
  24. for(int i=0;i<n;i++){
  25. g[i] = Integer.parseInt(a1[i]);
  26. }
  27. int max=0;
  28. for(int i=0;i<=n-k;i++){
  29. int sum=0;
  30. for(int j=i;j<i+k;j++){
  31. sum+=g[j];
  32. }
  33. if(sum>max)
  34. max=sum;
  35. }
  36. System.out.println(max);
  37. t--;
  38. }
  39.  
  40. }
  41. }
  42.  
Success #stdin #stdout 0.09s 27940KB
stdin
1
7 7
2 4 8 1 2 1 8
stdout
26