Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* [A][M][C][B][N] / [K][R][I][P][6][8] */
- #include <bits/stdc++.h>
- #include <unordered_map>
- using namespace std;
- typedef long long ll;
- const char sp = ' ', nl = '\n';
- const int MOD = 9973;
- ifstream fin("adunscad.in");
- ofstream fout("adunscad.out");
- vector<int> v, curr;
- int n, S, found(0);
- void back(int idx, int s = 0) {
- if (!found) {
- if (idx == n) {
- if (s == S) {
- found = true;
- if (curr[0] == -1) fout << '-';
- fout << v[0];
- for (int i = 1; i < n; ++i)
- fout << (curr[i] < 0 ? '-' : '+') << v[i];
- }
- }
- else {
- curr[idx] = 1;
- back(idx + 1, s + v[idx]);
- curr[idx] = -1;
- back(idx + 1, s - v[idx]);
- }
- }
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0), cout.tie(0);
- fin >> S >> n;
- v.resize(n), curr.resize(n);
- for (int i = 0; i < n; ++i)
- fin >> v[i];
- back(0);
- if (!found) fout << 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment