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 <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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 pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int t, res;
string msg;
vs reslog;

void dfs(int, string, vs);

int main(void){
    for(string num; cin >> t >> num, t;){
        res = -1;
        msg = "error";

        vs log;
        if(t == toInt(num)){
            res = t;
            msg = "ok";

            log.pb(num);
            reslog = log;
        }
        else dfs(0, num, log);
        
        if(msg == "ok"){
            cout << res;
            rep(i, reslog.size()){
                cout << " " << reslog[i];
            }
            cout << endl;
        }
        else{
            cout << msg << endl;
        }
    }

	return 0;
}

void dfs(int sum, string num, vs log){
    if(t < sum){
        return;
    }
    if(num.size() == 0){
        if(res == sum){
            msg = "rejected";
        }
        else if(res < sum){
            res = sum;
            reslog = log;
            msg = "ok";
        }

        return;
    }

    range(i, 1, num.size() + 1){
        string diff = num.substr(0, i);
        string nextnum = num.substr(i);

        //if(i != 1 && diff.at(0) == '0') continue;
        vs nextlog = log;
        nextlog.pb(diff);

        dfs(sum + toInt(diff), nextnum, nextlog);
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()

typedef pair<int, vector<int> > Paper;
Paper solve(int t, int num){
    string s = to_string(num);
    int L = (int)s.size() - 1;
    vector<Paper> cands;
    rep(i, 1<<L){
        vector<int> parts;
        for(int j=0; j<=L; ++j){
            string d = "";
            for(d+=s[j]; j<=L; ++j, d+=s[j])if(i >> j & 1)break;
            parts.push_back(stoi(d));
        }
        cands.emplace_back(accumulate(all(parts), 0), parts);
    }
    sort(all(cands));
    int k = count_if(all(cands), [&](const Paper& p){return p.first <= t;});
    if(k == 0)throw "error";
    if(count_if(cands.begin(), cands.begin() + k - 1,
                [&](const Paper& p){return p.first == cands[k-1].first;}))throw "rejected";
    return cands[k-1];
}

int main(){
    int t, num;
    while(cin >> t >> num, t|num){
        try{
            Paper ans = solve(t, num);
            cout << ans.first;
            for(const auto e: ans.second)cout << " " << e;
            cout << '\n';
        }catch(const char* mes){
            cout << mes << '\n';
        }
    }
    return 0;
}

C++: #include <stdio.h>
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll target;
    string s;
    cin>>target>>s;
    vector<ll> pow2(100,1);
    FOR(i,1,100){
      pow2[i]=pow2[i-1]*2;
    }


    while(target>0){
      ll size = s.size()-1;
      ll res = 0;
      ll flag = 2;
      ll res_bit = 0;
      deque<ll> ans;
      FOR(bit,0,pow2[size]){
        ll tmp_res = s[size] - '0';
        ll tmp = 1;
        deque<ll> tmp_ans;
        ll var = tmp_res;
        FOR(i,0,size){
          tmp *= 10;
          if(!(bit&(1<<(size-1-i)))) tmp = 1;
          ll x = s[size-i-1] - '0';
          tmp_res += x*tmp;
          if(tmp == 1){
             tmp_ans.push_back(var);
             var = 0;
          }
          var += x*tmp;
        }
        tmp_ans.push_back(var);


        if(tmp_res<=target){
          if(tmp_res == res) flag = 1;
          if(tmp_res>res){
            res = tmp_res;
            ans = tmp_ans;
            res_bit = bit;
            flag = 0;
          }
        }

      }
      if(flag == 0) {
        cout<<res;
        while(!(ans.empty())){
          cout<<" "<<ans.back();
          ans.pop_back();
        }
        cout<<endl;
      }
      else if(flag == 1) cout<<"rejected"<<endl;
      else cout<<"error"<<endl;

      cin>>target>>s;
    }
}