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. Scanner sc = new Scanner(System.in);
  12.  
  13.  
  14. int n=sc.nextInt();
  15. int l=sc.nextInt();
  16. int r=sc.nextInt();
  17. int nums[] = new int[n];
  18. for(int i=0; i<n; i++){
  19. nums[i]=sc.nextInt();
  20. }
  21.  
  22. int res = sumOfRange(l,r,nums);
  23. System.out.println(res);
  24. }
  25.  
  26. public static int sumOfRange(int l,int r, int []nums){
  27.  
  28. int p[] = new int[nums.length];
  29. p[0] = nums[0];
  30. for(int i=1;i<nums.length; i++){
  31. p[i] = p[i-1]+nums[i];
  32. }
  33. return p[r] - p[l-1];
  34.  
  35. }
  36. }
Success #stdin #stdout 0.11s 56556KB
stdin
6
2 5
3 4 1 2 1 4
stdout
8