Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n = 5;
- int a[n + 1];
- for (int i = 1; i <= n; ++i) {
- cin >> a[i];
- }
- int p[n + 1];
- p[0] = 0;
- int sum = 0;
- for (int i = 1; i <= n; ++i) {
- sum += a[i];
- p[i] = sum;
- }
- int L = 2, R = 4;
- cout << p[R] - p[L - 1] << '\n';
- }
- //1 2 3 4 5
- //1 2 3 4 5 = (L = 2, R = 4) => 9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement