-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFaultyPendulum.cpp
48 lines (40 loc) · 901 Bytes
/
FaultyPendulum.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
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
void applyAllDirection(vector<int> &forces, int initial, int ind, bool &flag) {
if ((unsigned)ind == forces.size() || initial == 0 || flag) {
if (flag) return;
if (initial == 0) flag = true;
return;
}
initial += forces[ind];
applyAllDirection(forces, initial, ind + 1, flag);
initial -= forces[ind];
initial -= forces[ind];
applyAllDirection(forces, initial, ind + 1, flag);
initial += forces[ind];
}
int main() {
int n;
cin >> n;
int initial;
cin >> initial;
string direction;
cin >> direction;
vector<int> forces;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
forces.push_back(temp);
}
bool ans = false;
applyAllDirection(forces, initial, 0, ans);
if (ans) {
cout << "Possible";
} else {
cout << "Not Possible";
}
return 0;
}