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;

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;

int solve(){
    int t;
    string s;
    cin >> t >> s;
    if(t == 0) return 1;
    int n = s.size(), ans = -1, maxi = -1;
    bool rejected = false;
    for(int S=0;S<1<<(n-1);S++){
        int sum = 0, d = 0;
        for(int i=0;i<n;i++){
            d = d*10+s[i]-'0';
            if((S>>i)&1){
                sum += d;
                d = 0;
            }
        }
        sum += d;
        if(sum <= t && sum > maxi){
            maxi = sum;
            ans = S;
            rejected = false;
        }else if(sum == maxi){
            rejected = true;
        }
    }
    if(rejected){
        cout << "rejected" << endl;
    }
    else if(ans >= 0){
        cout << maxi << " ";
        for(int i=0;i<n;i++){
            cout << s[i];
            if((ans>>i)&1) cout << " ";
        }
        cout << endl;
    }else{
        cout << "error" << endl;
    }
    return 0;
}

int main(){
    while(solve()==0);
    return 0;
}

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

int target;
string s;
int maxi;
vector<int> ans, parts;

void rec(int sum, int p) {
  if(sum > target) {
    return;
  }
  if(p == s.size()) {
    if(sum == maxi) {
      ans.clear();
    } else if(sum > maxi) {
      ans = parts;
      maxi = sum;
    }
    return;
  }
  for(int len = 1; p+len <= s.size(); ++len) {
    int part = atoi(s.substr(p, len).c_str());
    parts.push_back(part);
    rec(sum + part, p+len);
    parts.pop_back();
  }
}

int main() {
  while(cin >> target >> s && !(target == 0 && s == "0")) {
    maxi = -1;
    rec(0, 0);
    if(maxi == -1) cout << "error" << endl;
    else if(ans.empty()) cout << "rejected" << endl;
    else {
      cout << maxi;
      for(int i = 0; i < ans.size(); ++i) {
        cout << " " << ans[i];
      }
      cout << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
vector<int>res;
int ma,cnt;

void dfs(int s,const int t,const string n,vector<int>&v){
	if(s>t)return;
	if(n.empty()){
		if(ma<s)ma=s,cnt=0;
		if(ma==s)res=v,cnt++;
	}else if(n[0]=='0'){
		if(n.size()==1){
			v.push_back(0);
			dfs(s,t,n.substr(1),v);
			v.pop_back();
		}
	}else{
		int add=0;
		for(int i=0;i<n.size();i++){
			add=add*10+n[i]-'0';
			v.push_back(add);
			dfs(s+add,t,n.substr(i+1),v);
			v.pop_back();
		}
	}
}

int main(){
	int t;
	string n;
	for(;cin>>t>>n,t;){
		vector<int>v;
		ma=0,cnt=0;
		dfs(0,t,n,v);
		if(cnt>1)puts("rejected");
		else if(!ma)puts("error");
		else{
			printf("%d",ma);
			for(int i=0;i<res.size();i++)printf(" %d",res[i]);
			puts("");
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,l,a[10],ans,cnt;
string s;
int al[10],tal[10];
void d(int x,int sum,int nsum){
  if(x==l){
    sum+=nsum;
    if(ans==sum)cnt++;
    if(sum>ans&&sum<=n){
      ans=sum,cnt=1;
      for(int i=0;i<l;i++)tal[i]=al[i];
    }
    return;
  }
  if(sum>n)return;
  d(x+1,sum+nsum,a[x]);
  al[x]=1;
  d(x+1,sum,nsum*10+a[x]);
  al[x]=0;
}

int main(){
  while(cin>>n>>s){
    if(!n)break;
    int tn=n,sum=0;
    l=ans=0;
    cnt=1;
    for(int i=0;i<s.size();i++){
      al[i]=tal[i]=0;
      a[i]=s[i]-'0';
      sum+=a[i];
    }
    l=s.size();
    if(n<sum)cout<<"error"<<endl;
    else{
      d(1,0,a[0]);
      if(cnt==1){
	cout<<ans;
	for(int i=0;i<s.size();i++){
	  if(!tal[i])cout<<" ";
	  cout<<s[i];
	}
	cout<<endl;
      }
      else cout<<"rejected"<<endl;
    }
  }
  return 0;
}