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+1];
  16. int dp[]=new int[n+1];
  17.  
  18. for(int i=1;i<=n;i++)
  19. arr[i]=sc.nextInt();
  20.  
  21. for(int i=1;i<=n;i++)
  22. dp[i]=dp[i-1]+arr[i];
  23.  
  24.  
  25. int q=sc.nextInt();
  26. while(q-->0)
  27. {
  28. int val=sc.nextInt();
  29. System.out.println(dp[val]+" ");
  30. }
  31. }
  32. }
Success #stdin #stdout 0.17s 57000KB
stdin
3
1 2 3
1
3
stdout
6