Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
4
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define nn "\n"
#define ex exit(0);
#define sz(s) (int)(s).size();
bitset<100001>bk;
const int N= 1e7;
int n , t ;
int p(int x ){
    int bit =0 ;
    for(int i=  2 ; i <= sqrt(x) ; i++) {
        if (x % i == 0) {
            bit =1 ;
            break;
        }
    }
    return bit;
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n ;
    int m[n+1];
    ll p[n+1] , sf[n+1];
    p[0]= 0 , sf[0] =0 ;
    for(int i =1 ; i <= n ;i++){
        cin>>m[i];
        p[i] = p[i-1]+m[i];
    }
    for(int i = n  ; i>=1 ; i--) {
        sf[n - i + 1] = sf[n - i] + m[i];
    }
    int le = 1 , r = n - le;
    int bit =0 ;
    while(p[le+1]<sf[r-1] && r < n ){
        le++;
        r--;
    }
    while(p[le-1]>sf[r+1] && le>1 ){
        le--;
        r++;
    }
    for(int l = le ; l < n ; l++){
        if(p[l]>sf[n- l]){
            for(int i = 1; i<= l ; i++){
                if(p[l]-m[i]==sf[n - l]+m[i]){
                    cout <<"YES";
                    ex;
                }
            }
        }
        if(p[l]<sf[n-l] && n - l > 1 ){
            for(int i=  l + 1 ; i <= n ; i++){
                if(p[l]+m[i]==sf[n - l]-m[i]){
                    cout <<"YES";
                    ex;
                }
            }
        }
        if(p[l]==sf[n-l]){
            cout << "YES";
            ex;
        }
    }
    cout << "NO";


}