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 x=sc.nextInt();
  16. int y=sc.nextInt();
  17. int b[]=new int[n+1];
  18. for(int i=1;i<=n;i++)
  19. b[i]=sc.nextInt();
  20.  
  21.  
  22. int prefix[]=new int[n+1];
  23. for(int i=1;i<=n;i++)
  24. {
  25. if(i-y>=1)
  26. prefix[i]=b[i]+prefix[i-y];
  27. else
  28. prefix[i]=b[i];
  29.  
  30. }
  31.  
  32.  
  33. int g[]=new int[n+1];
  34.  
  35. for(int i=1;i<=n;i++)
  36. {
  37. if((i-(x-1)*y)>=1)
  38. {
  39. if((i-(x-1)*y)-y>=1)
  40. g[i]=prefix[i]-prefix[(i-(x-1)*y)-y];
  41. else
  42. g[i]=prefix[i];
  43.  
  44. }
  45. else
  46. g[i]=Integer.MAX_VALUE;
  47.  
  48. }
  49.  
  50. int ans=Integer.MAX_VALUE;
  51. for(int i=1;i<=n;i++)
  52. ans=Math.min(ans,g[i]);
  53.  
  54. System.out.println(ans);
  55.  
  56.  
  57.  
  58.  
  59. }
  60. }
Success #stdin #stdout 0.11s 54420KB
stdin
7
2
2
1 5 8 1 4 5 8
stdout
6