-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathDistribute_apples.cpp
62 lines (49 loc) · 1.45 KB
/
Distribute_apples.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
/*
Problem statement:
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna.
Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend.
Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts.
Please, tell him: is it possible to divide all the apples in a fair way between his friends?
*/
/* Solution: */
/*
Reference: https://codeforces.com/problemset/problem/433/A
*/
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
int a = 0, b = 0, val;
for(int i = 0; i < n; i++) {
cin >> val;
if(val == 100)
a++;
else b++;
}
if(a&1) {
cout << "NO" << endl;
} else {
if(a==0 && (b&1)) {
cout << "NO" << endl;
return 0;
}
if(b%2 == 0 || (b > a)) {
cout << "YES" << endl;
return 0;
}
int half = (a*100 + b*200)/2;
for(int i = 0; i <= b; i++) {
if((i*200 <= half && (half-i*200 <= a*100)))
{
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
return 0;
}