#include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n,m;
    int cnt;
    cin >> n >> m;
    int arr[n];
    int i[m];
    int j[m];
    for (int k =  0;k < n;k++ ) {
        cin >> arr[k];
    }
    for (int k =  0;k < m;k++) {
        cin >> i[k] >> j[k];
        cnt = 0;
        for (int b = i[k];b < j[k]+1;b++) {
            cnt += arr[b-1];
        }
        cout << cnt << "\n";
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: