Ganesh1648

PivotLinks

Sep 4th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define pb push_back
  6. #define forn(i, n) for (int i = 0; i < n; i++)
  7. #define ll long long
  8. #define endl "\n"
  9.  
  10. const int N = 2e5 + 5;
  11. void solve()
  12. {
  13.     int n;
  14.     cin>>n;
  15.     ll a[n];
  16.     forn(i,n)
  17.         cin>>a[i];
  18.     ll pref[n];
  19.     ll suff[n];
  20.     pref[0]=0;
  21.     suff[n-1]=0;
  22.     for(int i=1;i<n;i++)
  23.         pref[i]=a[i-1]+pref[i-1];
  24.     for(int i=n-2;i>=0;i--)
  25.         suff[i]=a[i+1]+suff[i+1];
  26.    
  27.     for(int i=0;i<n;i++)
  28.     {
  29.         if(pref[i]==suff[i])
  30.         {
  31.             cout<<i<<endl;
  32.             return;
  33.         }
  34.     }
  35. }
  36. int main()
  37. {
  38.     ios_base::sync_with_stdio(false);
  39.     cin.tie(NULL);
  40.     cout.tie(NULL);
  41.     solve();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment