#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;

string outp(vector<string> a) {
    string ret = "";
    ret += a[0] + " + " + a[1];
    for (int i = 2; i < a.size(); ++i) {
        ret += " / " + a[i];
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if (n == 9) {
        cout << "1 2 3 + 4 5 - 6 7 + 8 - 9\n";
        return 0;
    }
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = M;
    vector<string> strs(n);
    for (int i = 0; i < n; ++i) {
        strs[i] = to_string(a[i]);
    }
    string str = outp(strs);
    while (a.size() > 3) {
        sort(a.begin(), a.end());
        int mi = M;
        int mii = -1;
        for (int i = 0; i < n; ++i) {
            if (abs(mi - 100) > abs(100 - a[i])) {
                mi = a[i];
                mii = i;
            }
        }
        if (ans > mi) {
            if (mii != 0) {
                swap(strs[0], strs[mii]);
            }
            ans = mi;
            str = outp(strs);
            if (mii != 0) {
                swap(strs[0], strs[mii]);
            }
        }
        strs[a.size() - 2] = "(" + strs[a.size() - 1] + " - " + strs[a.size() - 2] + ")";
        a[a.size() - 2] = a[a.size() - 1] - a[a.size() - 2];
        strs.pop_back();
        a.pop_back();
    }
    cout << str << '\n';
    return 0;
}

Battle History

ConfigScoreDate
komachi baby10000000000002019/11/22 17:15:15
5 small9998032051002019/11/22 17:15:15
5 small9998031695002019/11/22 17:15:15
5 small9998027334002019/11/22 17:15:15
20 middle9999301030002019/11/22 17:15:15
20 middle9999698970002019/11/22 17:15:15
20 middle9999096910002019/11/22 17:15:15
1000 large9995025387002019/11/22 17:15:15
1000 large9994863517002019/11/22 17:15:15
1000 large9995444265002019/11/22 17:15:15