Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- int niza[n];
- int pref_sum[n];
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- sum += niza[i];
- pref_sum[i] = sum;
- }
- int q;
- cin >> q;
- for(int i = 0; i < q; i++) {
- int x, y;
- cin >> x >> y;
- if(x == 0) {
- cout << pref_sum[y] << endl;
- }
- else {
- cout << pref_sum[y] - pref_sum[x - 1] << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement