Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define forn(i, n) for (int i = 0; i < n; i++)
- #define ll long long
- #define endl "\n"
- const int N = 2e5 + 5;
- void solve()
- {
- int n;
- cin>>n;
- ll a[n];
- forn(i,n)
- cin>>a[i];
- ll pref[n];
- ll suff[n];
- pref[0]=0;
- suff[n-1]=0;
- for(int i=1;i<n;i++)
- pref[i]=a[i-1]+pref[i-1];
- for(int i=n-2;i>=0;i--)
- suff[i]=a[i+1]+suff[i+1];
- for(int i=0;i<n;i++)
- {
- if(pref[i]==suff[i])
- {
- cout<<i<<endl;
- return;
- }
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment