Advertisement
Josif_tepe

Untitled

Dec 17th, 2021
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.     int niza[n];
  8.     int prefix_sum[n];
  9.     int sum = 0;
  10.     for(int i = 0; i < n; i++) {
  11.         cin >> niza[i];
  12.         sum += niza[i];
  13.         prefix_sum[i] = sum;
  14.     }
  15.     for(int i = 0; i < n; i++) {
  16.         int leva_sum = 0;
  17.         if(i != 0) {
  18.             leva_sum = prefix_sum[i - 1];
  19.         }
  20.         int desna_sum = prefix_sum[n - 1] - prefix_sum[i];
  21.         if(leva_sum == desna_sum) {
  22.             cout << i + 1 << endl;
  23.             return 0;
  24.         }
  25.     }
  26.     cout << -1 << endl;
  27.    
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement