fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc=new Scanner(System.in);
  14. int n=sc.nextInt();
  15. int arr[]=new int[n];
  16. for(int i=0;i<n;i++) arr[i]=sc.nextInt();
  17.  
  18. int x=sc.nextInt();
  19. int y=sc.nextInt();
  20. int psum[]=new int[n+1];
  21. for(int i=1;i<=y;i++){
  22. psum[i]=arr[i-1];
  23. }
  24. for(int i=y+1;i<=n;i++){
  25. psum[i]=arr[i-1]+psum[i-y];
  26. }
  27. for(int i=1;i<=n;i++){
  28. System.out.println(psum[i]);
  29. }
  30. int min=Integer.MAX_VALUE;
  31. for(int i=n;i>=x*y;i--){
  32. int sum=psum[i]-psum[i-x*y];
  33. min=Math.min(min,sum);
  34. }
  35. System.out.println(min);
  36. }
  37. }
Success #stdin #stdout 0.11s 56420KB
stdin
7
1 5 8 1 4 5 8
2 2
stdout
1
5
9
6
13
11
21
6