Submission

Status:
PPPPPPPPPPPPPPPPPPPP

Score: 100

User: 17458

Problemset: ผลบวก (ง่าย)

Language: cpp

Time: 0.065 second

Submitted On: 2024-10-24 19:03:47

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n; cin >> n;
    vector<int> prefix(n,0);
    int x;
    for (int i = 0;i < n;i++) {
        cin >> x;
        if (i == 0) prefix[i] = x;
        else prefix[i] = x + prefix[i-1];
    }

    int l,r; cin >> l >> r;
    if (l == 0) cout << prefix[r];
    else cout << prefix[r] - prefix[l - 1];
}