Last active
November 12, 2017 20:28
-
-
Save izanbf1803/db7e61a91a21414d8b0a757df68801fc to your computer and use it in GitHub Desktop.
Solution to https://jutge.org/problems/P74421_en/statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
const int _1e5 = 100000; | |
int abs(int n) { return (n < 0 ? -n : n); } | |
int main() | |
{ | |
int n, q, a, b, res; | |
int bolets[_1e5 + 1]; | |
int cas = 0; | |
while (cin >> n) { | |
cas++; | |
for (int i = 0; i < n; i++) { | |
cin >> bolets[i]; | |
if (i > 0) bolets[i] += bolets[i - 1]; | |
} | |
cin >> q; | |
cout << '#' << cas << endl; | |
for (int i = 0; i < q; i++) { | |
cin >> a >> b; | |
res = bolets[max(a, b) - 1]; | |
if (min(a, b) - 2 >= 0) res -= bolets[min(a, b) - 2]; | |
cout << res << endl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment