Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:10000000000")
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <set>
- #include <vector>
- #include <map>
- #include <algorithm>
- using namespace std;
- pair <bool,int> c[10001];
- bool f[10001];
- int main()
- {
- #ifdef _DEBUG
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- #else
- // freopen("segments.in", "r", stdin);
- // freopen("segments.out", "w", stdout);
- #endif
- int n, a, b[10001], sum, i, j, ans, t;
- cin >> n >> a >> t;
- a -= t;
- n--;
- sum = 0;
- c[0].first = 1;
- for (i = 0; i < n; i++)
- {
- cin >> b[i];
- for (j = sum; j >= 0; j--)
- {
- if (c[j].first && !c[j + abs(b[i])].first)
- {
- c[j + abs(b[i])].first = 1;
- c[j + abs(b[i])].second = i;
- }
- }
- sum += abs(b[i]);
- }
- ans = 0;
- int ans_2 = sum + a;
- for (i = 0; i <= sum; i++)
- {
- if (c[i].first == 1 && abs(2 * i - ans_2) < abs(2 * ans - ans_2))
- {
- ans = i;
- }
- }
- cout << ans * 2 - sum + t << endl << t;
- while (ans > 0)
- {
- f[c[ans].second] = 1;
- ans -= abs(b[c[ans].second]);
- }
- for (i = 0; i < n; i++)
- {
- if (f[i]==1)
- {
- if (b[i] >= 0)
- {
- cout << '+' << b[i];
- }
- else
- {
- cout << '-' << b[i];
- }
- }
- else
- {
- if (b[i] >= 0)
- {
- cout << '-' << b[i];
- }
- else
- {
- cout << '+' << b[i];
- }
- }
- }
- #ifdef _DEBUG
- system("pause");
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement