fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int t;
  5. cin>>t;
  6. while(t--)
  7. {
  8. long long int n;
  9. cin>>n;
  10. long long int a[n];
  11. for(int i=0;i<n;i++){
  12. cin>>a[i];
  13. }
  14. long long int q;
  15. cin>>q;
  16. while(q--){
  17. int k,m,c=0;
  18. cin>>k>>m;
  19. for(int i=k;i<=m;i++){
  20. c+=a[i];
  21. }
  22. cout<<c<<" ";}
  23. cout<<"\n";
  24. }
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 5516KB
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