fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7.  
  8. vector<int> a(n);
  9.  
  10. for (int i = 0; i < n; i++) {
  11. cin >> a[i];
  12. }
  13.  
  14. int q;
  15. cin>>q;
  16. while(q--){
  17. int l,r;
  18. cin>>l>>r;
  19. long long sum=0;
  20.  
  21. for(int i=l; i<=r;i++){
  22. sum+=a[i];
  23. }
  24. cout<<sum<<endl;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 5316KB
stdin
5
10 20 30 40 50
4
0 2
1 4
2 2
3 4
stdout
60
140
30
90