题意:
思路:
这道题需要倒着步骤考虑,就是先去假设已经分为了两部分,这左右两部分的和相等,然后去想上一个步骤
倒着一个步骤后,可以发现这样的性质:
Code:
cpp
#include <bits/stdc++.h>
#define int long long
using i64 = long long;
constexpr int N = 1e5 + 10;
constexpr int M = 1e5 + 10;
constexpr int P = 2600;
constexpr i64 Inf = 1e18;
constexpr int mod = 1e9 + 7;
constexpr double eps = 1e-6;
int n;
int a[N];
void solve() {
std::cin >> n;
std::map<int,int> mp, mp2;
int sum = 0;
for (int i = 1; i <= n; i ++) {
std::cin >> a[i];
sum += a[i];
mp2[a[i]] ++;
}
if (sum & 1) {
std::cout << "NO" << "\n";
return;
}
int s = 0;
for (int i = 1; i <= n; i ++) {
s += a[i];
mp[a[i]] ++;
mp2[a[i]] --;
if (s > sum / 2) {
if (mp[s - sum / 2]) {
std::cout << "YES" << "\n";
return;
}
}else if (s < sum / 2) {
if (mp2[sum / 2 - s]) {
std::cout << "YES" << "\n";
return;
}
}else {
std::cout << "YES" << "\n";
return;
}
}
std::cout << "NO" << "\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
while (t--) {
solve();
}
return 0;
}