Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, m := io.NextInt(), io.NextInt()
		if n == 0 {
			break
		}
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = io.NextInt()
		}
		ans := 0
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] <= m {
					ans = intMax(a[i]+a[j], ans)
				}
			}
		}
		if ans == 0 {
			io.Println("NONE")
		} else {
			io.Println(ans)
		}
	}
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <iostream>
using namespace std;

int main(){
  while(1){
    int n,m; //個数 n、最大金額 m
    cin >> n >> m;
    if(n==0&&m==0) break;

    int a[n];
    for(int i=0; i<n; i++) cin >> a[i]; //品物の価格

    int ans = -1;
    for(int i=0; i<n; i++){
      for(int j=i+1; j<n; j++){
        if(a[i] + a[j] <= m){
          ans = max(ans, a[i] + a[j]);
        }
      }
    }
    if(ans == -1) cout << "NONE" << endl;
    else cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    // Your code here!
    
    while(1){
    int n = 0;
    int m = 0;
    scanf("%d %d",&n, &m);
    if(n==0 && m==0)break;
    int a[1000] = {0};
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    int max = 0;
    int koushin = 0;
    
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(max<a[i]+a[j] && m>=a[i]+a[j]){
                max = a[i]+a[j];
                koushin = 1;
            }
        }
    }
    
    if(koushin !=1){
        cout << "NONE" << endl;
    }
    else{
    cout << max << endl;
    }
    }

    return 0;
}

C++: /*Problem sennobushige 16D8104015E 18.5.16*/
#include <iostream>
#define N 100000

int main(){
  int n,max;
  int A[N]={0},k=0;


  while(n!=0){
    int p=0,tmp;
    std::cin>>n;
    int a[n]={0};
    std::cin>>max;
    if(n==0)break;
    for(int i=0;i<n;i++){
      std::cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
	tmp=a[i]+a[j];
	if(tmp>=A[k]&&tmp<=max){
	  A[k]=tmp;
	  p++; 
	}
      }
    }
    if(p==0) A[k]=0;
    k++;
    //if(p!=0) std::cout<<sum<<"\n";
    //else std::cout<<"NONE\n";
  }
  for(int i=0;i<k;i++){
    if(A[i]!=0){
      std::cout<<A[i]<<"\n";
    }else{
      std::cout<<"NONE\n";
    }
  }



}



/*実行結果
[16D8104015E@ise6bc jisen]$ ./Problem_A
3 45 
10 20 30
6 10
1 2 5 8 9 11
7 100
11 34 83 47 59 29 70
4 100
80 70 60 50
4 20
10 5 10 16
0 0
40
10
99
NONE
20
*/

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

int main(){
    while(1){
        int n, m;
        cin >> n >> m;
        if (!n) break;
        vector<int> a(n);
        for(int i = 0; i < n; i++) cin >> a[i];
        int ans = 0;
        for(int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                if (i != j && a[i] + a[j] <= m) ans = max(ans, a[i] + a[j]); 
            }
        }
        cout << ans << endl;    
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)

int main(void){
    int n,m;
    while(cin>>n>>m, n|m){
        vector<int> a(n);
        rep(i,n){
            cin>>a[i];
        }
        int res = 0;
        rep(i,n)rep(j,i){
            int sum = a[i]+a[j];
            if(sum <= m){
                res = max(res,sum);
            }
        }
        if(res == 0) cout<<"NONE"<<endl;
        else cout<<res<<endl;
    }    
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int n,m,a[1000];

map<int,int> c;

int main() {
    while(true) {
        cin >> n >> m;
        if(n == 0)break;
        rep(i,n){
            cin >> a[i];
            c[a[i]] = 0;
        }
        rep(i,n) {
            c[a[i]]++;
        }
        sort(a,a+n);//aをソート

        int ans = -1;
        rep(i,n) {
            int* itr = upper_bound(a,a+n,m - a[i]);//m-a[i]<a[j] となる最小のjのa[j]へのポインタを取得
            if(itr - a == 0) {//m - a[i]>=a[j]を満たすjが存在しない時
                continue;
            }
            itr--;//ポインタを一つ減算してm-a[i]>=a[j]となる最大のjのa[j]へのポインタを取得
            if(*itr == a[i] && c[a[i]] < 2) {//境界のものがa[i]だった時
                if(itr - a == 0) {//a[i]未満のものがない時
                    continue;
                }
                itr--;//さらに一つ前に
            }
            ans = max(ans,*itr + a[i]);
        }
        if(ans == -1)cout << "NONE" << endl;
        else cout << ans << endl;
    }

    return 0;
}

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

using ll = long long int;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

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

    while(1) {
        ll n, m;
        cin >> n >> m;
        if(!n) break;
        vector<ll> a(n);
        REP(i, n) cin >> a[i];

        ll ret = -1;
        REP(i, n) FOR(j, i+1, n) {
            if(a[i]+a[j] <= m) chmax(ret, a[i]+a[j]);
        }

        if(ret == -1) cout << "NONE" << endl;
        else cout << ret << endl;
     }

    return 0;
}

C++: #include<iostream>
#include<stdlib.h>

using namespace std;
const int MAX_N = 1024;

int kk[MAX_N*MAX_N + 1];

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(void) {
	int n, m, max = 0;
	int a[1024];

	cin >> n >> m;
	for(int i = 0; i < n; ++i)
		cin >> a[i];


	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			if(max < a[i] + a[j] && i != j && a[i] + a[j] < m)
			max = a[i] + a[j];

	qsort(kk, n * n, sizeof(int), compare_int);

	cout << max << endl;

}