-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNETEASE3.cpp
65 lines (58 loc) · 1.24 KB
/
NETEASE3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <vector>
using namespace std;
bool IsDivdable(const vector<int>& ring)
{
long long sum = 0;
for (auto e : ring) sum += e;
if (sum & 1) return false;
sum >>= 1;
// auto accmulate = [&ring](size_t i, size_t j) -> long
// {
// if (i > j) throw std::invalid_argument("invalide range");
// long ret = 0;
// for (size_t x = i; x <= j; ++x) ret += ring[x];
// return ret;
// };
size_t i = 0;
long long cur_sum = 0;
for (; i < ring.size(); ++i)
{
cur_sum += ring[i];
if (cur_sum == sum) return true;
else if (cur_sum > sum) break;
} // at this point: cur_sum > sum && prev_sum < sum
for (size_t j = 0; j < i && i < ring.size(); )
{
if (cur_sum == sum)
return true;
else if (cur_sum > sum)
cur_sum -= ring[j++];
else // cur_sum < sum
cur_sum += ring[i++];
}
return false;
}
int main()
{
int num_group;
cin >> num_group;
vector<string> ret;
while (num_group--)
{
int n;
cin >> n;
vector<int> ring;
for (int x; n--;)
{
cin >> x;
ring.push_back(x);
}
if (IsDivdable(ring))
ret.emplace_back("YES");
else
ret.emplace_back("NO");
}
for (auto& e : ret) cout << e << endl;
return 0;
}