fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. // your code goes here
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(NULL);
  10. cout.tie(0);
  11. int t;
  12. cin>>t;
  13. while(t--)
  14. {
  15. int ne;
  16. cin>>ne;
  17. int i;
  18. int arr[ne];
  19. for(i=0;i<ne;i++)
  20. {
  21. cin>>arr[i];
  22. }
  23.  
  24. int cases;
  25. cin>>cases;
  26. while(cases--)
  27. {
  28. long long m,n;
  29. cin>>m>>n;
  30. long long a,b,c=0;
  31. a=min(m,n);
  32. b=max(m,n);
  33. for(i=a;i<=b;i++)
  34. {
  35. c=c+arr[i];
  36. }
  37. cout<<c<<" ";
  38.  
  39. }
  40. cout<<"\n";
  41. }
  42.  
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5552KB
stdin
2
6
9 0 1 3 2 -6
4
1 3
2 5
3 4
0 5
3
2 4 6
2
0 1
1 2
stdout
4 0 5 9 
6 10