Problem:
Taro's Shopping
Mammy decided to give Taro his first shopping experience.
Mammy tells him to choose any two items he wants from those
listed in the shopping catalogue,
but Taro cannot decide which two, as all the items look attractive.
Thus he plans to buy the pair of two items with
the highest price sum, not exceeding the amount Mammy allows.
As getting two of the same item is boring, he wants two different items.
You are asked to help Taro select the two items.
The price list for all of the items is given.
Among pairs of two items in the list,
find the pair with the highest price sum
not exceeding the allowed amount,
and report the sum.
Taro is buying two items, not one, nor three, nor more.
Note that, two or more items in the list may be priced equally.
Input
The input consists of multiple datasets, each in the following format.
n
m
a
1
a
2
...
a
n
A dataset consists of two lines.
In the first line, the number of items
n
and the maximum
payment allowed
m
are given.
n
is an integer satisfying 2 ≤
n
≤ 1000.
m
is an integer satisfying 2 ≤
m
≤ 2,000,000.
In the second line, prices of
n
items are given.
a
i
(1 ≤
i
≤
n
) is the price
of the
i
-th item.
This value is an integer greater than or equal to 1 and
less than or equal to 1,000,000.
The end of the input is indicated by a line containing two zeros.
The sum of
n
's of all the datasets does not exceed 50,000.
Output
For each dataset, find the pair with the highest price sum
not exceeding the allowed amount
m
and output the sum in a line.
If the price sum of every pair of items exceeds
m
,
output
NONE
instead.
Sample Input
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
Output for the Sample Input
40
10
99
NONE
20

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  while(true){
    int n, m;
    cin >> n >> m;
    if(!n) break;

    vector<int> price(n);
    for(auto& i:price) cin >> i;

    int ans = -1;

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        if(price[i] + price[j] > m) continue;
        if(price[i] + price[j] > ans) ans = price[i] + price[j];
      }
    }
    
    if(ans == -1) cout << "NONE" << endl;
    else cout << ans << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3368
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

template <typename A>
void chmin(A &l, const A &r) {
    if (r < l)
        l = r;
}
template <typename A>
void chmax(A &l, const A &r) {
    if (l < r)
        l = r;
}

ll mod = 998244353;

ll n, m;
vector<ll> v;
void input() {
    cin >> n >> m;
    v.resize(n);
    for (auto &x : v) cin >> x;
}

void solve() {
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (v[i] + v[j] <= m) {
                chmax(ans, v[i] + v[j]);
            }
        }
    }

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

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

    while (1) {
        input();
        if (n == 0)
            break;
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3408
final_rank: 16

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

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

		if (n == 0 && m == 0)
			break;

		vector<int> a(n);
		rep(i, n) 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;
}
accuracy: 1
time_ms: 10
memory_kb: 3056
final_rank: 2

code_snippet: #include <iostream>
#include <cmath>
using namespace std;

const int MAX_N = 1000;
int n, m, ans;
int a[MAX_N];

int main() {
    while (cin >> n >> m) {
        if (n == 0 && m == 0)
            break;
        ans = 0;
        for (int i = 0; i < n; i++)
            cin >> a[i];
        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)
            cout << ans << endl;
        else
            cout << "NONE" << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3100
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
   using ll=long long;
   using vl=vector<ll>;
   using vll=vector<vl>;
    int n=1,m;
    while(n!=0){
        cin>>n>>m;
        if(n==0 && m==0){
            break;
        }
        vl s(n);
        for(int i=0;i<n;i++){
            cin>>s.at(i);
        }
        int r=0;
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                if(s.at(i)+s.at(j)<=m){
                    if(s.at(i)+s.at(j)>r){
                        r=s.at(i)+s.at(j);
                    }
                }
            }
        }
        if(r==0){
            cout << "NONE" <<endl;
        }
        else{
            cout<<r<<endl;
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3312
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(i=0;i<N;i++)
#define ll long long

int main(void){
    vector<ll>ans;
    ll i,j,k;

    for(;;){
        ll N,M;
        ll A[1009];
        cin>>N>>M;
        if(N==0&&M==0)break;
        rep(i,N)cin>>A[i];
        ll a=-1;
        rep(i,N){
            for(j=i+1;j<N;j++){
                ll sum=A[i]+A[j];
                if(M<sum)continue;
                a=max(a,sum);
            }
        }
        ans.push_back(a);
    }

    rep(i,ans.size()){
        if(ans[i]==-1){
            cout<<"NONE"<<endl;
            continue;
        }
        cout<<ans[i]<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3164
final_rank: 8

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
const int INF = 2001001001;
const ll LINF = 9001001001001001001;

#define rep(i, n) for (int i = 0; (i) < (n); (i)++)
#define rep1(i, n) for (int i = 1; (i) < (n + 1); (i)++)
#define all(a) (a).begin(), (a).end()

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

    if(!n && !m) break; 

    int a[n];
    rep(i,n) cin >> a[i];

    int ans = 0;
    rep(i,n){
      for(int j = i+1; j < n; j++){
        if(a[i] + a[j] <= m) ans = max(ans, a[i] + a[j]);
      }
    }
    if(ans) cout << ans << endl;
    else cout << "NONE" << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3436
final_rank: 17

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

    int n,m,l;
    bool end = false;
    int q = 0;
    vector<string> result(1000);
    while(end == false){
    l = 0;
    cin >> n >> m;
    if(n==0 && m== 0){
        /*rep(i,q){
            cout << result[i] << endl;
        }*/
        end = true;
    }else{
    vector<int> a(n);
    for(ll i = 0; i < n ;i++){
        //cout<< i << endl;
        cin >> a.at(i);
        //cout<< i << endl;
    }
    //cout<< "終わり" << endl;
    for (ll i = 0; i < n; i++)
    {
        //cout<< i << endl;
        for(int j = 0; j < n; j++)
        {
            if(l < a[i] + a[j] ){
                if(a[i] + a[j] <= m){
                    if(i!=j){
                        l = a[i] + a[j];
                    }


                }
            }

        }

    }
    if(l != 0 && l <= m){
        //result[q]=to_string(l);
        cout << l << endl;
    }
    if(l == 0){
       // result[q]="NONE";
       cout << "NONE" << endl;
    }
    q++;
    

    }

}
}
accuracy: 1
time_ms: 10
memory_kb: 3376
final_rank: 14

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

    int n,m,l;
    bool end = false;
    int q = 0;
    vector<string> result(1000);
    while(end == false){
    l = 0;
    cin >> n >> m;
    if(n==0 && m== 0){
        rep(i,q){
            cout << result[i] << endl;
        }
        end = true;
    }else{
    vector<int> a(n);
    for(ll i = 0; i < n ;i++){
        //cout<< i << endl;
        cin >> a.at(i);
        //cout<< i << endl;
    }
    //cout<< "終わり" << endl;
    for (ll i = 0; i < n; i++)
    {
        //cout<< i << endl;
        for(int j = 0; j < n; j++)
        {
            if(l < a[i] + a[j] ){
                if(a[i] + a[j] <= m){
                    if(i!=j){
                        l = a[i] + a[j];
                    }


                }
            }

        }

    }
    if(l != 0 && l <= m){
        result[q]=to_string(l);

    }
    if(l == 0){
        result[q]="NONE";
    }
    q++;
    

    }

}
}
accuracy: 1
time_ms: 10
memory_kb: 3236
final_rank: 9

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

int main() {
    int n,m;
    cin>>n>>m;
    while(n||m){
        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;
        cin>>n>>m;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3052
final_rank: 1

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

int main() {
	while (1)
	{
		int	n, m;
		cin >> n >> m;
		if (!n && !m)
			break ;
		vector<int> a(n);
		rep(i, 0, n) cin >> a[i];

		int	max = 0;
		rep(i, 0, n - 1)
		{
			rep(j, i + 1, n)
			{
				if (a[i] + a[j] <= m && a[i] + a[j] > max)
					max = a[i] + a[j];
			}
		}
		if (!max)
			cout << "NONE" << endl;
		else
			cout << max << endl;
	}
	return (0);
}
accuracy: 1
time_ms: 10
memory_kb: 3352
final_rank: 11

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

int main(){
    vector<int> vec;
while(true){
    int n, m;
    if(n == 0 && m == 0){
        break;
    }
    cin >> n >> m;
    int a[n];
    rep(i,n) cin >> a[i];
    int ans = -1;
    rep(i,n){
        rep(j,n){
            if(i != j && a[i] + a[j] <= m){
                ans = max(a[i] + a[j] , ans);
            }
        }
    }    
    vec.push_back(ans);
}
    int k = vec.size();
        rep2(i,k-1){
        if(vec[i] == -1) cout << "NONE" << endl;
            else cout << vec[i] << endl;
        }
        return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3060
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (int)s; i < (int)(n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    
    vector<int> a(n);
    rep(i, n) {
      cin >> a[i];
    }

    int ans = 0;
    rep(i, n) {
      rep(j, n) {
        if (i == j) continue;
        int sum = a[i] + a[j];
        if (sum <= m) chmax(ans, sum);
      }
    }

    if (ans == 0) {
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3448
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define Graph vector<vector<int>>
#define pii pair<int, int>

int main(){

    while(true){
        int n, m;
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        vector<int> vec(n);
        rep(i, n){
            cin >> vec[i];
        }
        int ans=0;
        rep(i, n){
            rep(j, n){
                if(i == j) continue;
                if(vec[i]+vec[j] <= m){
                    ans = max(ans, vec[i]+vec[j]);
                }
            }
        }
        if(ans == 0){
            cout << "NONE" << endl;
        }else{
            cout << ans << endl;
        }
   }
}
accuracy: 1
time_ms: 10
memory_kb: 3096
final_rank: 5

code_snippet: #include <bits/stdc++.h>
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
#define all(x) (x).begin(), (x).end()
#define rep1(a)          for(ll i = 0; i < a; i++)
#define rep2(i, a)       for(ll i = 0; i < a; i++)
#define rep3(i, a, b)    for(ll i = a; i < b; i++)
#define rep4(i, a, b, c) for(ll i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define vvl(a,b,c) vector<vector<ll>>(a,vector<ll>(b,c))
#define vvvl(a,b,c,d) vector<vector<vector<ll>>>(a,vvl(b,c,d))
#define enld endl
#define fix(n) cout << fixed << setprecision(n);
#define yesno(b) cout << (b ? "Yes":"No") << endl
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>using rp_queue=priority_queue<T,vector<T>,greater<T>>;
void fast_io(){cin.tie(nullptr);ios_base::sync_with_stdio(false);}
const int inf = INT_MAX / 2;
const ll infl = 1LL<<60;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int dx[8] = {0, 1, 0,-1, 1, 1,-1,-1};
const int dy[8] = {1, 0,-1, 0, 1,-1, 1,-1};

int main() {
    fast_io();
    for(;;) {
        int N,M; cin >> N >> M;
        if(N==0) break;
        vector<ll>A(N); rep(N) cin >> A[i];
        ll ans = 0;
        rep(i,N) rep(j,N) if(i!=j && A[i]+A[j]<=M) chmax(ans,A[i]+A[j]);
        if(ans==0) cout << "NONE" << enld;
        else cout << ans << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3476
final_rank: 19

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

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];
        }

        vector<int>sum(0);
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                sum.push_back(a[i]+a[j]);
            }
        }
        sort(sum.begin(),sum.end());

        // for(int i=0;i<sum.size();i++){
        //     cout << sum[i] << " ";
        // }
        // cout << endl;
        auto it = upper_bound(sum.begin(),sum.end(),m);
        // cout << it-sum.begin() << endl;
        if(it-sum.begin()==0){
            cout << "NONE" << endl;
        }else{
            cout << sum[it-sum.begin()-1] << endl;
        }
    }
}
accuracy: 1
time_ms: 190
memory_kb: 6996
final_rank: 20

code_snippet: #include <bits/extc++.h>
using namespace std;

bool solve();

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

bool solve() {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) return false;
    vector<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 = 0; j < n; j++) {
            if (i == j) continue;
            if (a[i] + a[j] <= m) ans = max(ans, a[i] + a[j]);
        }
    }

    if (ans == -1) puts("NONE");
    else cout << ans << endl;
    return true;
}
accuracy: 1
time_ms: 10
memory_kb: 3092
final_rank: 4

code_snippet: #include<iostream>
using namespace std;

int main(){
    int n,m,sum,x;
    int ans;
    while(true){
        cin >> n >> m;
        ans=0;
        if(n==0 && m==0){
            break;
        }
        int array[n];
        for(int i=0;i<n;i++) cin >>  array[i];
        for(int i=0;i<n;i++){
            for(int j=0;j<n; j++){
                sum=array[i] + array[j];
            if(
                sum<=m && ans<sum && i!=j)ans=sum;
            }
        }
        if(ans!=0){
             cout << ans << endl;
        }else{
        cout << "NONE" << endl;
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3120
final_rank: 7

code_snippet: #include <iostream>
#include <algorithm>

using namespace std;
int main() {
    while (true){
        int 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 = 0; j < n; j++) {
                int current = a[i] + a[j];
                if (i == j) continue;
                if (ans < current && current <= m) {
                    ans = current;
                }
            }
        }
        if (ans == -1) cout << "NONE" << endl;
        else cout << ans << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3368
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
int ctoi(char c){return c-'0';}
ll ctoll(char c){return c-'0';}

void solve(int n,int m){
     vector<int>a(n);
     int ans = -1;
     rep(i,n)cin >> a[i];
     rep(i,n)rep(j,n){
          if(i==j)continue;
          if(ans < a[i]+a[j]){
               if(a[i]+a[j]<=m)ans = a[i]+a[j];
          }
     }
    if(ans == -1)cout << "NONE" << endl;
    else cout << ans << endl;
}

int main(){
     while(true){
          int n,m;
          cin >> n >> m;
          if(n==0&&m==0)break;
          solve(n,m);
     }
}
accuracy: 1
time_ms: 10
memory_kb: 3380
final_rank: 15