Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
520 B
0
Indexable
Never
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;


int main()
{
    int n;
    cin >> n;
    int sum = 0;
    vector<int> pref_sum;
    vector<int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        sum += v[i];
        pref_sum.push_back(sum);
    }
    
    int S, E;
    cin >> S >> E;
    if(S == 0) {
        cout << pref_sum[E] << endl;
    }
    else {
        cout << pref_sum[E] - pref_sum[S - 1] << endl;
    }
    return 0;
}