-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path816.cpp
64 lines (54 loc) · 1003 Bytes
/
816.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
#include <cstdio>
#include <algorithm>
#define MAX 1005
using namespace std;
bool compare(int i, int j){ return !(i<j); }
int main(){
int v[MAX], n, x, y, tot,t;
t = 1;
while(scanf("%d %d %d",&x,&y,&n) && x){
tot = x+y;
int tesouro = 0;
for(int i = 0; i < n; i++){
scanf("%d",&v[i]);
tot += v[i];
tesouro += v[i];
}
printf("Teste %d\n",t);
if(tot % 2 != 0)
printf("N\n\n");
else{
sort(v,v + n,compare);
int obj = tot/2;
int j;
for(j = 0; j < n; j++){
int res = v[j];
for(int k = 0; k < n; k++){
if(k != j && res + v[k] + x <= obj)
res += v[k];
}
if(res + x == obj){
printf("S\n\n");
break;
}
}
if(j == n) {
for(j = 0; j < n; j++){
int res = v[j];
for(int k = 0; k < n; k++){
if(k != j && res + v[k] + y <= obj)
res += v[k];
}
if(res + y == obj){
printf("S\n\n");
break;
}
}
if(j == n)
printf("N\n\n");
}
}
t++;
}
return 0;
}