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