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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

#define REP(i, n) for ( int i = 0; i < n; i++ )
#define NIL -1

using namespace std;

int N, maxVal;
vector<vector<int> > ans;

int getFigure(int num) {
    if(num == 0) return 1;

    int ret = 0;
    while(num > 0) {
        num /= 10;
        ret++;
    }
    return ret;
}

void merge(vector<int> &nums, int idx) {
    int nonZero = 0,
        prevIdx = 0;
    REP(i, nums.size()) {
        if(nums[i] == NIL) continue;
        nonZero++;

        if(nonZero == idx + 2) {
            int step = getFigure(nums[i]);
            REP(j, step) nums[prevIdx] *= 10;
            nums[prevIdx] += nums[i];
            nums[i] = NIL;
            break;
        }
        prevIdx = i;
    }
}

int sum(vector<int> &nums) {
    int ret = 0;
    REP(i, nums.size()) if(nums[i]!=NIL) ret += nums[i];
    return ret;
}

void dump(vector<int> &nums) {
    REP(i, nums.size()) cout << nums[i] << ",";
    // REP(i, nums.size()) if(nums[i]!=NIL)cout << nums[i] << ",";
    cout << endl;
}

bool equal(vector<int> &a, vector<int> &b) {
    int ai = 0, bi = 0;
    REP(i, a.size()) {
        while(a[ai] == NIL) ai++;
        while(b[bi] == NIL) bi++;

        // cout << "ai:" << ai << ", bi:" << bi << endl;
        if(a[ai] != b[bi]) return 0;

        i = ai + 1;
        ai++; bi++;
    }
    return 1;
}

void solve(vector<int> &nums, int d = 0) {
    int s = sum(nums);

    if(d > nums.size()) return;
    if(s > N) return;

    if(s == maxVal && !equal(ans[0], nums)) {
        // cout << "最大値更新:" << maxVal << ", " << equal(ans[0], nums);
        // dump(ans[0]);
        // cout << endl;
        ans.push_back(nums);
    } else if (s > maxVal) {
        ans.clear();
        ans.push_back(nums);
        maxVal = s;
    }

    vector<int> base = nums;
    REP(i, nums.size() - (d+1)) {
        // cout << "hoge" << endl;
        merge(nums, i);
        solve(nums, d+1);
        nums = base;
    }
}

int main() {
    int num;
    vector<int> nums;

    while(cin >> N >> num, N||num) {

        maxVal = -1;
        ans.clear();
        nums.clear();

        while(num > 0) {
            nums.push_back(num % 10);
            num /= 10;
        }
        reverse(nums.begin(), nums.end());

        // cout << N << ", " << num << ", " << ans.size() << ", " << maxVal << endl;

        // dump(nums);
        // merge(nums, 0);

        // dump(nums);
        // merge(nums, 1);
        solve(nums);

        if(ans.size() == 0) {
            cout << "error" << endl;
        } else if (ans.size() >= 2) {
            cout << "rejected" << endl;
        } else {
            cout << sum(ans[0]);
            REP(i, ans[0].size()) if(ans[0][i] != NIL) cout << " " << ans[0][i];
            cout << endl;
        }
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<sstream>
using namespace std;
int o;
string str;
int t;
string num;
int rej;
int s2i(string s){
  istringstream ss(s);
  int x;
  ss >> x;
  return x;
}
void rec(int n,string s,int v){
  //cout << n << ":"<<v <<endl;
  if(n==num.size()-1){
    if(v>o&&v<=t) {
      o=v;
      str=s;
      rej=0;
    }else if(o==v){
      rej=1;
    }
  }
  string buf;
  //buf+=num[n];
  for(int i=n+1;i<num.size();i++){
    buf+=num[i];
    //cout << s2i(buf) <<endl;
    rec(i,s+" "+buf,v+s2i(buf));
  }
}
int main(){
  cin >> t >> num;
  while(num[0]!='0'){
    o=-1;
    rej=0;
    string buf;
    for(int i=0;i<num.size();i++){
      buf+=num[i];
      //cout << s2i(buf) <<endl;
      rec(i," "+buf,s2i(buf));
    }
    //rec(0,0,num[0]-'0');

    if(o==-1) cout << "error" << endl;
    else if(rej==1) cout << "rejected" <<endl;
    else cout << o << str << endl;
    cin >> t >> num;
  }
}

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

using namespace std;

int t; string num;
int ans;
bool rej;
vector<int> avec;

void solve(int idx, int sum, vector<int> vec)
{
  if(idx == num.size()){
    if(ans < sum && sum <= t) ans = sum, avec = vec, rej = false;
    else if(ans == sum) rej = true;
    return;
  }
  for(int i = 1; i <= num.size() - idx; i++){
    vector<int> tmp = vec;
    tmp.push_back(stoi(num.substr(idx, i)));
    solve(idx + i, sum + stoi(num.substr(idx, i)), tmp);
  }
  return;
}

int main()
{
  while(cin >> t >> num, t || num != "0"){
    ans = -1;
    rej = false;
    vector<int> vec;
    solve(0, 0, vec);
    if(rej) cout << "rejected" << endl;
    else if(ans < 0) cout << "error" << endl;
    else{
      cout << ans;
      for(int i = 0; i < avec.size(); i++) cout << " " << avec[i];
      cout << endl;
    }
  }
  return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int t;
		string s;
		cin >> t >> s;
		if (!t)break;
		int n = s.size(), cnt = 0, cmax = -1;
		vi ans;
		REP(i, (1 << n - 1)) {
			int sum = 0;
			int tmp = 0;
			vi x;
			REP(j, n) {
				tmp *= 10;
				tmp += s[j] - '0';
				if (i & 1 << j) {
					sum += tmp;
					x.push_back(tmp);
					tmp = 0;

				}
			}
			sum += tmp;
			x.push_back(tmp);
			if (sum <= t) {
				if (sum == cmax)cnt++;
				else if (sum > cmax) {
					cnt = 1;
					cmax = sum;
					ans = x;
				}
			}
		}
		if (cmax == -1)cout << "error" << endl;
		else if (cnt > 1)cout << "rejected" << endl;
		else {
			cout << cmax << " ";
			DUMP(ans);
		}
	}
	return 0;
}