fork download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Main
  5. {
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(System.in);
  8. int n=sc.nextInt();
  9. int[]nums =new int[n];
  10. for(int i=0;i<n;i++){
  11. nums[i]=sc.nextInt();
  12. }
  13.  
  14. int y=sc.nextInt();
  15. int x=sc.nextInt();
  16.  
  17.  
  18. int[] prefix=new int[n];
  19. prefix[0]=nums[0];
  20.  
  21. int[] answer = new int[n];
  22. for(int i=1;i<n;i++){
  23. if(i-y >= 0){
  24. prefix[i]=nums[i]+prefix[i-y];
  25. }
  26. else{
  27. prefix[i]=nums[i];
  28. }
  29. }
  30. int res= Integer.MAX_VALUE;
  31.  
  32. for(int i=x*y-y;i<n;i++){
  33. if(i-x*y >= 0){
  34. answer[i]=prefix[i]-prefix[i-x*y];
  35. res = Math.min(res,answer[i]);
  36. }
  37. else{
  38. answer[i]=prefix[i];
  39. res = Math.min(res,answer[i]);
  40. }
  41. }
  42. System.out.print(res);
  43.  
  44.  
  45. }
  46. }
Runtime error #stdin #stdout #stderr 0.11s 56652KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.base/java.util.Scanner.throwFor(Scanner.java:937)
	at java.base/java.util.Scanner.next(Scanner.java:1594)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
	at Main.main(Main.java:8)