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;

void quickSort(int* Array,int left,int right){
    if(left >= right)return;
    int i=left,j=right;
    int pivod = Array[(left+right)/2];
    while(1){
        while(Array[i]<pivod)
            i++;
        while(Array[j]>pivod)
            j--;
        if(i>=j)break;
        swap(Array[i],Array[j]);
        i++;j--;
    }
    quickSort(Array,left,i-1);
    quickSort(Array,j+1,right);
}
int main(){
    int n,m;
    while(true){
        cin>>n>>m;
        if(n==0 && m==0)break;
        int goods[n];
        for(int i=0;i<n;i++){
            cin>>goods[i];
        }
        quickSort(goods,0,n-1);
        int mst_expe = 0;
        int i=0,j=n-1;
        while(i<j){
            if(goods[i]+goods[j] <= m){
                if(mst_expe < goods[i]+goods[j]){
                    mst_expe = goods[i]+goods[j];
                    i++;
                    continue;
                }
            }
            j--;
        }
        if(mst_expe==0)cout<<"NONE"<<endl;
        else cout<<mst_expe<<endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,m,max=0;
  while(1){
    max=0;
    bool flag=false;
    cin>>n>>m;
    if(n==0&&m==0){
      break;
    }
    int a[n];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
  
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	  if(max<a[j]+a[k] && a[j]+a[k]<=m&&j!=k){
	    max=a[j]+a[k];
	    flag=true;
	  }
      }
    }
    if(flag==false){
      cout<<"NONE"<<endl;
    }else{
      cout<<max<<endl;
    }
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0)break;
		vector<int> A(n);
		for(int i = 0; i < n; i ++)cin >> A[i];
		int ans = 0;
		for(int i = 0; i < n - 1; i ++){
			for(int j = i + 1; j < n; j ++){
				if(A[i] + A[j] <= m)ans = max(ans, A[i] + A[j]);
			}
		}
		if(ans == 0)cout << "NONE" << endl;
		else cout << ans << endl;
	}

	return 0;
}

C++: #include <iostream>
#define MAX 50000

int main(){
    int set[MAX];
    int i_set = 0;
    int n, m;
    std::cin >> n >> m;

    while(n != 0 && m != 0){
        int flag = 0;
        int item[n];
        for(int i=0; i<n; i++){
            std::cin >> item[i];
        }
        int max1, max2;
        if(item[0] > item[1]){
            max1 = item[0];
            max2 = item[1];
        }
        else{
            max1 = item[1];
            max2 = item[0];
        }
        int i=2;
        int max = max1 + max2;
        while(max > m){
            if(item[i] <= max2){
                max2 = item[i];
            }
            else if(item[i] <= max1){
                max1 = item[i];
                max1 = max2;
            }
            max = max1 + max2;
            i += 1;
            if((i == n) && (max > m)){
                set[i_set] = -1;
                i_set += 1;
                flag = 1;
            }
        }
        if(flag == 0){
            for(int j=i; j<n; j++){
                if((item[j] >= max1) && ((item[j]+max1) <= m)){
                    max1 = item[j];
                    max2 = max1;
                }
                else if((item[j] >= max1) && ((item[j]+max2) <= m)){
                    max1 = item[j];
                }
                else if((item[j] >= max2) && ((item[j]+max1) <= m)){
                    max2 = item[j];
                }
                else if(((item[j]) >= max2) && ((item[j]+max2) <= m)){
                    max1 = item[j];
                }
            }
            max = max1 + max2;
            set[i_set] = max;
            i_set += 1;
        }
        std::cin >> n >> m;
    }

    for(int k=0; k<i_set; k++){
        if(set[k] == -1){
            std::cout << "NONE\n";
        }
        else{
            std::cout << set[k] << '\n';
        }
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);
    if (a[n - 1] + a[n - 2] < m) {
      cout << a[n - 1] + a[n - 2] << endl;
      continue;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int p = lower_bound(a, a + n, m - a[i]) - a;
      while (a[i] + a[p] > m || i == p)
        p--;
      if (p > 0 && a[i] + a[p] > ans)
        ans = a[i] + a[p];
    }
    if (ans)
      cout << ans << endl;
    else
      cout << "NONE" << endl;
  }
}

C++: #include<cstdio>

int main(){
  int n,m;
  int A[10000];
  int max;
  bool flag = 1;

  std::scanf("%d %d",&n,&m);
  
  for(int i = 0;i < n;i++){
    std::scanf("%d",&A[i]);
  }
  
  max = A[0] + A[1];

  if(max > m){
    flag = 0;
  }
  
  for(int i = 0;i < n;i++){
    for(int j = i + 1;j < n;j++){
      if(max < A[i] + A[j] && (A[i] + A[j]) <= m){
	max = A[i] + A[j];
	flag = 0;
      }
    }
  }
  if(flag){
    std::printf("%d\n",max);
  }else{
    std::printf("NONE\n");
  }

  return 0;
}