Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int ar[200001];
- long long arr[200001];
- // bool fn(int n,vector<int> arr){
- // int sum=0;
- // for(int i=0;i<n;i++)sum+=arr[i];
- // bool bo=false;int xx=sum%3;
- // map<int,int> mp;
- // for(int i=0;i<n;i++){
- // int x=arr[i]%3;
- // mp[x]=1;
- // }
- // if(mp[1]&&mp[2])mp[0]=1;
- // if(mp[xx])return true;
- // return false;
- // }
- bool solve()
- {
- int n;
- cin>>n;
- for(int i=1;i<=n;i++)
- {
- cin>>ar[i];
- arr[i] = arr[i-1] + ar[i];
- }
- long long s1 = 0, s3 = 0;
- int i = 1, j = n;
- bool ok = 0;
- while(i < j)
- {
- if(s1 == s3)
- {
- if((arr[j-1] - arr[i]) == s1)
- {
- ok = 1;
- break;
- }
- else
- {
- s1 += ar[i];
- s3 += ar[j];
- i++;
- j--;
- }
- }
- else if(s1 < s3)
- {
- s1 += ar[i];
- i++;
- }
- else
- {
- s3 += ar[j];
- j--;
- }
- }
- return ok;
- }
- int main() {
- cout<<solve()<<"\n";
- return 0;
- }
Add Comment
Please, Sign In to add comment