Go: // Package main provides
//
// File:  1237.go
// Author: ymiyamoto
//
// Created on Wed Jul 11 10:35:26 2018
//
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func comb(ns []string, aux [][]string) [][]string {
	if len(ns) == 0 {
		return aux
	}
	v := ns[0]
	a := [][]string{}
	for _, au := range aux {
		tmp := make([]string, len(au))
		copy(tmp, au)
		tmp[len(tmp)-1] += v
		a = append(a, tmp)

		au = append(au, v)
		a = append(a, au)
	}

	return comb(ns[1:], a)
}

func main() {
	for {
		var d int
		var num string
		fmt.Scan(&d, &num)
		if d == 0 {
			break
		}

		var min int
		ns := strings.Split(num, "")
		for i := range ns {
			v, _ := strconv.Atoi(ns[i])
			min += v
		}

		var ans int
		var pat []string
		var hasSame bool
		for _, c := range comb(ns[1:], [][]string{{ns[0]}}) {
			var total int
			for _, v := range c {
				n, _ := strconv.Atoi(v)
				total += n
			}
			if ans == total {
				hasSame = true
			} else if ans < total && total <= d {
				ans = total
				pat = c
				hasSame = false
			}
		}

		if ans == 0 {
			fmt.Println("error")
		} else if hasSame {
			fmt.Println("rejected")
		} else {
			fmt.Println(ans, strings.Join(pat, " "))
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int T;
string S;
vector<int> sep;
int ans;
bool rejected;

int stoi(int s, int t){
    int res = 0;
    for(int i=s; i<t; i++)
        res = res * 10 + S[i]-'0';
    
    return res;
}

string itos(int s, int t){
    return S.substr(s, t-s);
}

void dfs(int s, vector<int> split, int sum){
    //????????????
    int tans = sum + stoi(s, S.size());
    if(tans <= T){
        if(ans == tans)
            rejected = true;
        if(ans < tans){
            ans = tans;
            rejected = false;
            sep = split;
        }
    }
    
    //????????????
    for(int i=s+1; i<S.size(); i++){
        auto tsplit = split;
        tsplit.push_back(i);
        dfs(i, tsplit, sum + stoi(s, i));
    }
}

void solve(){
    dfs(0, {}, 0);
    
    if(ans == -1){
        cout << "error" << endl;
    }else if(rejected){
        cout << "rejected" << endl;
    }else{
        cout << ans;
        sep.insert(sep.begin(), 0);
        sep.push_back(S.size());
        for(int i=1; i<sep.size(); i++){
            cout << " " << itos(sep[i-1], sep[i]);
        }
        cout << endl;
    }
}

int main(){
    while(cin >> T >> S, T){
        ans = -1;
        rejected = false;
        sep.clear();
        solve();
    }
    
    return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	int s;
	string r;
	vi n;
	state(int s, string r, vi n) : s(s), r(r), n(n) {};
	bool operator<(const state &o)const {
		return s<o.s;
	}
};

int main() {
	int t;
	string num;
	
	while(cin >> t >> num, t) {
		stack<state> S;
		S.push(state(0, num, vi()));
		vector<state> res;
		while(!S.empty()) {
			state st = S.top();
			S.pop();

			if(t < st.s) {
				continue;
			}
			
			if(st.r.size() == 0) {
				res.push_back(st);
				continue;
			}

			int size = st.r.size();
			//if(st.r[0] == '0') {
			//	vi nn = st.n;
			//	nn.push_back(0);
			//	S.push(state(st.s, st.r.substr(1, size), nn));
			//	continue;
			//} else {
				FOR(i, 1, size) {
					vi nn = st.n;
					string nr = st.r.substr(i);
					int ns = st.s + toInt(st.r.substr(0, i));
					nn.push_back(toInt(st.r.substr(0, i)));
					S.push(state(ns, nr, nn));
				}
			//}
		}

		sort(RALL(res));
		if(res.size() == 0) {
			cout << "error" << endl;
		} else if(res.size() > 1 && res[0].s == res[1].s) {
			cout << "rejected" << endl;
		} else {
			cout << res[0].s;
			REP(i, res[0].n.size()) {
				cout << " " << res[0].n[i];
			}
			cout << endl;
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;

string s;
int t,na;
bool reject;
vector<int> ra;

void dfs(int sum,int pos,vector<int> &ans) {
    if(sum > t) return;
    if(pos == s.length()) {
        if(na == sum) reject = true;
        if(na < sum) {
            reject = false;
            na = sum;
            ra = ans;
        }
        return;
    }

    for(int i=0; i<s.length()-pos; ++i) {
        int tmp = atoi(s.substr(pos,i+1).c_str());
        ans.push_back(tmp);
        dfs(sum+tmp, pos+i+1, ans);
        ans.pop_back();
    }
}

int main() {
    while(cin>>t>>s) {
        if(t == 0 && s == "0") break;
        na = -1;
        reject = false;

        vector<int> r;
        dfs(0, 0, r);

        if(reject) cout<<"rejected"<<endl;
        else if(na == -1) cout<<"error"<<endl;
        else {
            cout<<na;
            for(int i=0; i<ra.size(); ++i) cout<<" "<<ra[i];
            cout<<endl;
        }
    }
}