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>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
#define sz(n)  (int)n.size()
#define dump(x) cerr<<#x<<" = "<<(x)<<endl;
#define debug(x)cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define MP make_pair
#define PB push_back
//	priority_queue<int,vector<int>,greater<int>() >ta;
	int n,m;
	const int BIG=2000000;
	string sn,sm;
	int ans=0;
	bool used[BIG];
	bool flag[100];
	vector<string>ab;
	
	void dfs(int h,int f){
		if(h==sz(sm)){
		//for(int i=0;i<sz(sm);i++)cout<<flag[i]<<" ";cout<<endl;
		int sum=0;
		string tmp="";
		flag[sz(sm)-1]=0;
		for(int i=0;i<sz(sm);i++){
			tmp.push_back(sm[i]);
			if(flag[i])sum+=stoi(tmp),tmp="";
		}
		if(sz(tmp)>=1)sum+=stoi(tmp);
		if(f==1&&sum==ans){
			//for(int i=0;i<sz(sm);i++)cout<<flag[i]<<" ";cout<<endl;
			tmp="";
			for(int i=0;i<sz(sm);i++){
			tmp.push_back(sm[i]);
			if(flag[i]){ab.push_back(tmp),tmp="";}
		}
		if(!tmp.empty())ab.push_back(tmp);
		return ;
		}
		
		
		if(sum<=n)ans=max(ans,sum);
		used[sum]++;
		//for(int i=0;i<sz(sm);i++)cout<<flag[i]<<" ";cout<<sum<<endl;
		return ;
		}
		
		flag[h]=1;
		dfs(h+1,f);
		flag[h]=0;
		if(h+1<sz(sm))dfs(h+1,f);
	}
	
	
	int main(){
	while(cin>>n>>m,n||m){
	sn=itos(n),sm=itos(m);
	fill(used,used+BIG,0);
	fill(flag,flag+100,0);
	ans=0;
	ab.clear();
	dfs(0,0);
	if(used[ans]>=2)cout<<"rejected"<<endl;
	else if (ans==0)cout<<"error"<<endl;
	else {
		cout<<ans<<" ";
		dfs(0,1);
		for(int i=0;i<sz(ab);i++){cout<<ab[i];(i==sz(ab)-1)?cout<<"\n":cout<<" ";}
	}
	}
	return 0;
}

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

int t,Max,ng;
string num;
vector<int> ans,s;

void dfs(vector<int> v,int k){
    if (k==num.size()){
        int sum=accumulate(v.begin(),v.end(),0);
        if (t<sum) return;
        else if (Max<sum){
            Max=sum,ng=0;
            ans=v;
        } else if (Max==sum) ng=1;
        return;
    }
    if (!v.empty()){
        v.back()=v.back()*10+(num[k]-'0');
        dfs(v,k+1);
        v.back()/=10;
    }
    v.emplace_back(num[k]-'0');
    dfs(v,k+1);
}

void solve(){
    ans.clear();
    Max=0; ng=0;
    dfs(s,0);
    if (!Max) cout << "error" << '\n';
    else if (ng) cout << "rejected" << '\n';
    else {
        cout << Max;
        for (int x:ans) cout << ' ' << x;
        cout << '\n';
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> t >> num,t){
        solve();
    }
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int t;
string s;

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>t>>s;
		if(t==0)break;
		int res=-1;
		bool rejected=false;
		vector<string> ans;
		rep(i,1<<(s.length()-1)){
			string ss="";
			vector<string> a;
			int sum=0;
			rep(j,s.length()-1){
				ss+=s[j];
				if(i>>j&1){
					sum+=stoi(ss);
					a.pb(ss);
					ss="";
				}
			}
			ss+=s[s.length()-1];
			a.pb(ss);
			sum+=stoi(ss);
			if(sum<=t){
				if(res==sum)rejected=true;
				else if(res<sum){
					res=sum;rejected=false;
					ans=a;
				}
			}
		}
		if(rejected)cout<<"rejected"<<endl;
		else if(res==-1)cout<<"error"<<endl;
		else{
			cout<<res;
			rep(i,ans.size())cout<<" "<<ans[i];
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int t, num;
    cin >> t >> num;
    if (t == 0 && num == 0){
      break;
    }
    int mx = 0;
    int cnt = 0;
    string S = to_string(num);
    int N = S.size();
    vector<int> ans;
    for (int i = 0; i < (1 << (N - 1)); i++){
      vector<int> p(1, 0);
      for (int j = 0; j < N; j++){
        p.back() = p.back() * 10 + S[j] - '0';
        if (j < N - 1){
          if (i >> j & 1){
            p.push_back(0);
          }
        }
      }
      int sum = 0;
      for (int x : p){
        sum += x;
      }
      if (sum <= t){
        if (sum > mx){
          mx = sum;
          ans = p;
          cnt = 1;
        } else if (sum == mx){
          cnt++;
        }
      }
    }
    if (mx == 0){
      cout << "error" << endl;
    } else if (cnt >= 2){
      cout << "rejected" << endl;
    } else {
      cout << mx;
      for (int x : ans){
        cout << ' ' << x;
      }
      cout << endl;
    }
  }
}