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>
#include<string>
#include<queue>
#include<utility>

using namespace std;

int main(){

  int n,m,l=0,ans[25000]={0};
  int a[1000]={0};

  while(n!=0 && m!=0){
    cin>>n>>m;
    //  cout<<n<<" "<<m<<endl;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  /* for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
  }
  */
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){

      if(i!=j && a[i]+a[j]<=m && a[i]+a[j]>ans[l]){
	  ans[l]=a[i]+a[j];
	}     
      
    }
  }

 
 
 
  l++;
  }
     

  for(int i=0;i<l-1;i++){
  if(ans[i]!=0){
    cout<<ans[i]<<endl;
  }else{
    cout<<"NONE"<<endl;
  }
  }


return 0;
}

C++: #include <iostream>
#include <cmath>
#include <utility>
#include <functional>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int n, m;
	cin >> n >> m;

	while (n) {
		vector<int> price(n);
		rep(i, 0, n) cin >> price[i];

		SORT(price);
		REV(price);
		int ans = -1;
		rep(i, 0, n - 1) {
			rep(j, i + 1, n) {
				int sum = price[i] + price[j];
				if (sum <= m) ans = max(ans, sum);
			}
		}
		if (ans == -1) cout << "NONE" << endl;
		else cout << ans << endl;

		cin >> n >> m;
	}

	return 0;
}

C++: #include<stdio.h>

int ans[1000];


int main() {

	int n,m,c = 0;
	int MAX;
	int s[1000];

	while (1) {
		MAX = 0;
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0) break;

		for (int i = 0; i < n; i++) {
			scanf("%d", &s[i]);
		}
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
					if (MAX < s[i] + s[j] && m >= s[i] + s[j]) {
						MAX = s[i] + s[j];
				}
			}
		}
		if (MAX == 0) MAX = -1;
		ans[c] = MAX;
		c++;
	}

	for (int i = 0; i < 1000; i++) {
		if (ans[i] == 0) break;
		else if (ans[i] == -1) printf("NONE\n");
		else printf("%d\n", ans[i]);
	}

	return 0;
}

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

using namespace std;

int main(){

  int n,m;
  vector<int> a(1000);
  int sum=0;
  int max=0;
  
  while(1){
	cin>>n>>m;
	  
	  if(n == 0 && m  == 0)
		break;
	
	for(int i=0;i<n;++i)
	  cin>>a[i];
	
	for(int i=0;i<n-1;++i){
	  for(int j=i+1;j<n;++j){
	   
		sum=a[i]+a[j];
		
		if(sum>max && sum<=m)
		  max = sum;
			
	  }
	}

	if(max == 0)
	  cout<<"NONE"<<endl;
	else
	  cout<<max<<endl;
	
  }

  return 0;
}

C++: # Taro's Shopping

Problem URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1616

## Problem

You are required to answer some questions.

For each question, you are given $n$ integers $a_1, a_2, \dots, a_n$ and an integer $m$. You are required to find a pair of element $(a_i, a_j)$ where $a_i \not = a_j$, $a_i + a_j \leq m$ and the value of $a_i + a_j$ is maximal.

If there isn't a pair $(a_i, a_j)$ such that $a_i + a_j \leq m$, then output `NONE`. Otherwise, output $a_i + a_j$.

## Solution

We are required to find the largest pair with sum not exceeding $M$.

Let us assume that we have already chosen one item $a_i$, and we need to choose another item. What is the best item that we can choose? Obviously, it is the **largest number not greater than** $m - a_i$.

How can we do this quickly? As we know that sorting the array doesn't affect the answer, we should first sort the array and use binary search to find the best item.

Therefore, we can answer each query by first choosing each item once in $a_1, a_2, \dots, a_n$, then choose the best item available when one item is already chosen.

The time complexity is $O(n \log n)$ for a single question. As $\sum n < 50000$, this is fast enough to pass the problem.

## Code

```cpp
#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);
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int p = lower_bound(a, a + n, m - a[i]) - a;
      if (a[i] + a[p] >= m)
        p--;
      if (i == p)
        p--;
      if (p < 0) continue;
      if (a[i] + a[p] > ans)
        ans = a[i] + a[p];
    }
    if (ans)
    	cout << ans << endl;
    else
    	cout << "NONE" << endl;
  }
}
```

C++: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int n, m;
	while(cin >> m >> n, n || m){
		vector<int> data(n);
		for(int i = 0; i < n; i++){//input
			cin >> data[i];
		}

		int max = 0;
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				int tmp = data[i] + data[j];
				if(tmp <= m && tmp > max){
					max = tmp;
				}
			}
		}

		if(max == 0){//output
			cout << "NONE" << endl;
		} else {
			cout << max << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,m,b,max=0;
  while(n!=0 && m!=0){
    vector<int> a;
    max=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
      cin>>b;
      a.push_back(b);
    }
  
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	if(j!=k){
	  if(max<a[j]+a[k] && a[j]+a[k]<=m){
	    max=a[j]+a[k];
	    cout<<max<<"\n";
	  }
	}
      }
    }
    a.clear();
    if(max==0 && n!=0&&m!=0){
      cout<<"NONE"<<endl;
    }else if(n!=0&&m!=0){
      cout<<max<<endl;
    }
  }
}