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;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
ll t;
string num;
ll  ans;
int dp[1010101];
void dfs(int current,int amari, int cnt){
  if(current == num.size() && cnt == 0){
    dp[amari]++;
    return;
  }

  // 区切る場合
  int mm = cnt*10 + (num[current]-'0');
  if(amari - mm >= 0) dfs(current+1, amari-mm, 0);
  else return;

  // 区切らない場合
  if(current+1 < num.size()) dfs(current+1, amari, mm);

}

VI ansDFS(int current, int amari, int cnt, VI v){
  VI notAns;
  if(current == num.size()){
    if(ans == amari && cnt == -1) {
      return v;
    }
    else return notAns;
  }
  cnt = max(0,cnt);
  VI ansV0;
  VI ansV1;

  int mm = cnt*10 + (num[current]-'0');
  if(amari - mm < 0) return notAns;

  // 区切らない場合
  if(not(current > 0 && num[current] == '0' && num[current-1] == '0')) ansV0 = ansDFS(current+1, amari, mm, v);

  // 区切る場合
  v.push_back(mm);
  // cout << mm << endl;
  ansV1 = ansDFS(current+1, amari-mm, -1,v);

  if(ansV0.size() > 0) return ansV0;
  else return ansV1;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  while(true){
    cin >> t >> num;
    if(t == 0 && num == "0") break;


    rep(j,1010101) dp[j] = 0;
    dfs(0,t,0);
    bool flag = false;

    rep(i,t+1){
      if(dp[i] == 1){
        ans = i;

        VI v;
        VI ansV = ansDFS(0, t ,0, v);
        ans = t - ans;
        cout << ans << " ";
        // cout << "Vsize is " << ansV.size() << endl;
        rep(j,ansV.size()){
          if(ansV.size() == j+1) cout << ansV[j] << endl;
          else cout << ansV[j] << " ";
        }

        flag = true;
        break;
      }else if(dp[i] > 1){
        cout << "rejected" << endl;
        flag = true;
        break;
      }
    }
    if(flag == false){
      cout << "error" << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int s2i(string s){
    stringstream ss;
    ss << s;
    int ret;
    ss >> ret;
    return ret;
}
int main(){
    while(true){
        string target,input;
        cin >> target >> input;
        if(target == "0") break;
        int itarget = s2i(target);

        if(input.length() == 1){
            int iinput = s2i(input);
            if(iinput <= itarget){
                cout << iinput << " " << iinput << endl;
            }else{
                cout << "error" << endl;
            }
        }else{
            int N = input.size()-1;

            int maxi = -1;
            bool reject = false;
            vector<string> ans;
            for(int i=0;i<(1 << N);i++){
                vector<string> cutup;
                int before=0;
                for(int j=0;j<N;j++){
                    if(i & (1 << j)){
                        cutup.push_back(input.substr(before,j-before+1));
                        before = j+1;
                    }
                }
                cutup.push_back(input.substr(before));
                // for(int j=0;j<cutup.size();j++){
                //     cerr << cutup[j] << " ";
                // }
                // cerr << endl;
                int nyan = 0;
                for(int i=0;i<cutup.size();i++){
                    nyan += s2i(cutup[i]);
                }
                if(nyan > itarget) continue;
                if(maxi == nyan){
                    reject = true;
                }else if(nyan > maxi){
                    maxi = nyan;
                    ans = cutup;
                    reject = false;
                }
            }
            if(reject){
                cout << "rejected" << endl;
            }else if(maxi == -1){
                cout << "error" << endl;
            }else{
                cout << maxi;
                for(int i=0;i<ans.size();i++){
                    cout << " " << ans[i];
                }
                cout << endl;
            }
        }
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#define F for(int j=0;j<date;j++)
using namespace std;
int main(void){
	int t;
	string s;
	while(1){
		cin>>t>>s;
		if(t==0)break;
		int date=s.size();
		vector<int> a(date,0);
		for(int i=0;i<date;i++){
			a[i]=s[i]-'0';
		}
		int sum=0;
		vector<int> c(date,-1);
		vector<bool> ans(date,false);
		int n=1;
		for(int i=0;i<date;i++){
			n*=2;
		}
		int time=0;
		for(int i=0;i<n;i++){
			int x=i;

			int k=0;
			vector<int> d(date,-1);
			vector<bool> b(date,false);
			F{
				if(x%2==1){
					b[j]=true;
				}
			//	x-=x%2;
				x/=2;
			}
			int num=0,sum1=0;
		//	if(b[date-1])cout<<"ok"<<endl;
			F{
				if(b[j]){
					k*=10;
					k+=a[j];
				}else{
					sum1+=k;
				if(j!=0){
						d[num]=k;
						num++;
				}						
					k=a[j];
					
				}
				
			}
			sum1+=k;
			d[num]=k;
			if(sum1==sum){
				time++;
				//	cout<<sum<<' '<<sum1<<endl;;
	//	F{
	//					if(c[j]!=-1)cout<<c[j];
	//			if(j!=date-1)cout<<' ';
	
		
	//	}
	//	cout<<endl;
			}
			if(sum1<=t&&sum1>sum){
				sum=sum1;
				F{
					ans[j]=b[j];
					c[j]=d[j];
				}
				time=1;


			}
		}
		if(sum==0){
			cout<<"error"<<endl;
			continue;
		}
		if(time>2){
			cout<<"rejected"<<endl;
			continue;
		}
		cout<<sum<<' ';
		F{
			//if(!ans[j]){
			//	cout<<a[j];
			//}else{
			//	cout<<a[j];
				if(c[j]!=-1){
					cout<<c[j];
				if(j!=date-1)cout<<' ';
				}
		
		}
		cout<<endl;
	}

	return 0;	
}