Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- vector<int> pref_sum;
- int n;
- int suma(int i, int j) {
- if(j < 0 or j >= n) {
- return 0;
- }
- if(i - 1 < 0) {
- return pref_sum[j];
- }
- return pref_sum[j] - pref_sum[i - 1];
- }
- int main() {
- cin >> n;
- int niza[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- }
- int sum = 0;
- for(int i = 0; i < n; i++) {
- sum += niza[i];
- pref_sum.push_back(sum);
- }
- for(int i = 0; i < n; i++) {
- int S = 0;
- int E = i - 1;
- int sum_left = suma(S, E);
- S = i + 1;
- E = n - 1;
- int sum_right = suma(S, E);
- if(sum_left == sum_right) {
- cout << i + 1 << endl;
- return 0;
- }
- }
- cout << -1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement