Advertisement
Josif_tepe

Untitled

Apr 6th, 2024
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.     int n;
  10.     cin >> n;
  11.    
  12.     int niza[n];
  13.     int pref_sum[n];
  14.     int sum = 0;
  15.     for(int i = 0; i < n; i++) {
  16.         cin >> niza[i];
  17.         sum += niza[i];
  18.        
  19.         pref_sum[i] = sum;
  20.     }
  21.    
  22.     int q;
  23.     cin >> q;
  24.     for(int i = 0; i < q; i++) {
  25.         int x, y;
  26.         cin >> x >> y;
  27.        
  28.         if(x == 0) {
  29.             cout << pref_sum[y] << endl;
  30.         }
  31.         else {
  32.             cout << pref_sum[y] - pref_sum[x - 1] << endl;
  33.         }
  34.     }
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement