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