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 <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
	while(true){
		int n;
		string s;
		cin >> n >> s;
		if(n == 0 && s == "0"){ break; }
		const int m = s.size();
		vector< vector<int> > dp(m + 1, vector<int>(n + 1));
		vector< vector<int> > pr(m + 1, vector<int>(n + 1));
		vector< vector<int> > df(m + 1, vector<int>(n + 1));
		dp[0][0] = 1;
		for(int i = 0; i < m; ++i){
			int x = 0;
			for(int j = i; j < m; ++j){
				x = (x * 10) + s[j] - '0';
				if(x > n){ break; }
				for(int k = 0; k + x <= n; ++k){
					if(dp[i][k] == 0){ continue; }
					dp[j + 1][k + x] += dp[i][k];
					pr[j + 1][k + x] = i;
					df[j + 1][k + x] = x;
				}
			}
		}
		int answer = -1;
		for(int i = n; answer < 0 && i >= 0; --i){
			if(dp[m][i] != 0){ answer = i; }
		}
		if(answer < 0){
			cout << "error" << endl;
		}else if(dp[m][answer] >= 2){
			cout << "rejected" << endl;
		}else{
			cout << answer;
			vector<int> cut;
			int r = m, c = answer;
			do {
				const int d = df[r][c];
				cut.push_back(d);
				r = pr[r][c];
				c -= d;
			} while(r > 0);
			for(int i = cut.size() - 1; i >= 0; --i){
				cout << " " << cut[i];
			}
			cout << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdlib>
#include <vector>

using namespace std;
int t;
string str;

int ans;
int cnt;

vector<string> v;

bool rec(int x, int p) {
  bool flag = false;
  if(x > t) return false;
  if(p == str.length()) {
    if(x > ans) {
      v.clear();
      ans = x;
      cnt = 1;
      return true;
    } else if(x == ans) {
      cnt++;
      return false;
    }
    return false;
  }
  for(int i = 1; p+i <= str.length(); i++) {
    string s = str.substr(p, i);
    if(rec(x + atoi(s.c_str()), p+i)) {
      v.push_back(s);
      flag = true;
    }
  }
  return flag;
}

void solve() {
  ans = -1;
  rec(0, 0);
  if(ans == -1) cout << "error" << endl;
  else if(cnt != 1) cout << "rejected" << endl;
  else {
    cout << ans;
    for(int i = v.size()-1; i >= 0; i--) {
      cout << " " << v[i];
    }
    cout << endl;
  }
}

main() {
  while(( cin >> t >> str ) && (t || (str != "0"))) {
    solve();
  }
}

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

string str;
int t,ans;
bool f;
vector<int> ansv;

void solve(int n, int pos, vector<int> v){
  int a = 0;
  for(int i=pos;i<str.size();i++){
    vector<int> v2 = v;
    a *= 10;
    a += str[i] - '0';
    v2.push_back(a);
    if(n + a > t) return;
    if(i != str.size() - 1) solve(n+a, i+1, v2);
  }
  v.push_back(a);
  if(n + a > ans){
    ans = n + a;
    ansv = v;
    f = false;
  } else if(n + a == ans) f = true;
}

int main(){
  while(cin >> t >> str){
    if(t == 0 && str == "0") break;
    f = false;
    ans = -1;
    ansv.clear();
    solve(0,0,vector<int>(0,0));
    if(ans == -1) cout << "error" << endl;
    else if(f) cout << "rejected" << endl;
    else {
      cout << ans;
      for(int i=0;i<ansv.size();i++) cout << ' ' << ansv[i];
      cout << endl;
    }
  }
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */





template<class Type>
Type solve(Type res = Type()){
    ll t;
    string num;
    while(cin >> t >> num,t){
        map<ll,int> mp;
        
        function<void(int,int,int)> rec1 = [&](int n,int tsum,int sum){
            if(tsum + sum > t) return;
            if(n == num.length()){
                sum += tsum;
                mp[sum]++;
                return;
            }
            rec1(n+1,tsum*10 + (num[n]-'0'),sum);
            rec1(n+1,(num[n]-'0'),sum+tsum);
        };
        rec1(1,num[0]-'0',0);
        
        if(mp.empty()){
            cout << "error" << endl;
            continue;
        }
        if(mp.rbegin()->second >= 2){
            cout << "rejected" << endl;
            continue;
        }
        
        
        vector<int> ans;
        function<bool(int,int,int)> rec2 = [&](int n,int tsum,int sum){
            if(tsum + sum > t) return false;
            if(n == num.length()){
                if(sum+tsum == mp.rbegin()->first){
                    ans.push_back(tsum);
                    return true;
                }
                return false;
            }
            if(rec2(n+1,tsum*10 + (num[n]-'0'),sum)){
                return true;
            }
            if(rec2(n+1,(num[n]-'0'),sum+tsum)){
                ans.push_back(tsum);
                return true;
            }
            return false;
        };
        rec2(1,num[0]-'0',0);
        
        ans.push_back(mp.rbegin()->first);
        reverse(ans.begin(), ans.end());
        cout << ans << endl;
    }
    return res;
}


int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}