#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<iostream>
#include<sstream>

using namespace std;

int n, k;
int a[10000], b[10000];

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    scanf("%d%d", &n, &k);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    for(int i=0; i<n; i++) b[i] = a[i];
    sort(b, b+n); reverse(b, b+n);
    int v = b[k-1];
    printf("%d\n", v);
    for(int i=0; i<n; i++) {
        if(a[i] >= v) {
            if(k > 0) {
                printf("%d", i+1);
                k--;
                if(k == 0) printf("\n"); else printf(" ");
            }
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <algorithm>
#include <stdio.h>

using namespace std;

int main()
{int n,k,num,i;
	freopen("input.txt","r", stdin);
	freopen("ouput.txt","w", stdout);

	scanf("%d%d", &n, &k);

	vector<int> a;

	for(i=0; i<n; i++)
	{
		scanf("%d", &num);
		a.push_back(num);
	}

	vector<int> vec(a);

	sort(vec.begin(),vec.end(),greater<int>());

	//for(i=0; i<n; i++)
	//	cout<<vec[i]<<" ";

	num = vec[k-1];

	printf("%d\n", num);

	for(i=0; i<n && k>0; i++)
	{ //cout<<"k:"<<k;
		if(a[i] >= num)
			{printf("%d ", i+1);
			k--;
			}

	}
	printf("\n");

return 0;

}


#include <bits/stdc++.h>
#define sf(x) scanf("%d",&x)
#define sfd(x) scanf("%lf",&x)
#define sfbig(x) scanf("%I64d",&x)
#define sfbig2(x,y) scanf("%I64d%I64d",&x,&y)
#define pfbig(x) printf("%I64d\n",x)
#define sf2(x,y) scanf("%d%d",&x,&y)
#define sfc(x) scanf("%c",x)
#define pf(x) printf("%d\n",x);
#define EPS 1e-7
#define MOD 1000000007
#define kbir 1000
#define pi 3.14159265359
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
bool visited[1000000];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,k;
    sf2(n,k);
    multimap<int,int>m;
    vector<int>v(n);
    for (int i=0;i<n;i++)
    {
        sf(v[i]);
        m.insert({v[i],i+1});
    }
    sort(v.rbegin(),v.rend());
    v.resize(k);
    cout<<v[v.size()-1]<<endl;
    multimap<int,int>::iterator it;
    for (int i=0;i<v.size();i++)
    {
        int  cur=v[i];
        for (it=m.begin();it!=m.end();it++)
        {
            if (cur==it->first&&!visited[it->second])
            {
                cout<<it->second<<" ";
                visited[it->second]=1;
                break;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define sf(x) scanf("%d",&x)
#define sfd(x) scanf("%lf",&x)
#define sfbig(x) scanf("%I64d",&x)
#define sfbig2(x,y) scanf("%I64d%I64d",&x,&y)
#define pfbig(x) printf("%I64d\n",x)
#define sf2(x,y) scanf("%d%d",&x,&y)
#define sfc(x) scanf("%c",x)
#define pf(x) printf("%d\n",x);
#define EPS 1e-7
#define MOD 1000000007
#define kbir 1000
#define pi 3.14159265359
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,k;
    sf2(n,k);
    map<int,int>m;
    vector<int>v(n);
    for (int i=0;i<n;i++)
    {
        sf(v[i]);
        m[v[i]]=i+1;
    }
    sort(v.rbegin(),v.rend());
    v.resize(k);
    cout<<v[v.size()-1]<<endl;
    for (int i=0;i<k;i++)
        cout<<m[v[i]]<<" ";
    return 0;
}


#include <bits/stdc++.h>
#define sf(x) scanf("%d",&x)
#define sfd(x) scanf("%lf",&x)
#define sfbig(x) scanf("%I64d",&x)
#define sfbig2(x,y) scanf("%I64d%I64d",&x,&y)
#define pfbig(x) printf("%I64d\n",x)
#define sf2(x,y) scanf("%d%d",&x,&y)
#define sfc(x) scanf("%c",x)
#define pf(x) printf("%d\n",x);
#define EPS 1e-7
#define MOD 1000000007
#define kbir 1000
#define pi 3.14159265359
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
bool visited[1000000];
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,k;
    sf2(n,k);
    map<int,int>m;
    vector<int>v(n);
    for (int i=0;i<n;i++)
    {
        sf(v[i]);
        m[v[i]]=i+1;
    }
    sort(v.rbegin(),v.rend());
    v.erase(unique(v.begin(),v.end()),v.end());
    v.resize(k);
    cout<<v[v.size()-1]<<endl;
    for (int i=0;i<k;i++)
        cout<<m[v[i]]<<" ";
    return 0;
}


#include <bits/stdc++.h>
#define sf(x) scanf("%d",&x)
#define sfd(x) scanf("%lf",&x)
#define sfbig(x) scanf("%I64d",&x)
#define sfbig2(x,y) scanf("%I64d%I64d",&x,&y)
#define pfbig(x) printf("%I64d\n",x)
#define sf2(x,y) scanf("%d%d",&x,&y)
#define sfc(x) scanf("%c",x)
#define pf(x) printf("%d\n",x);
#define EPS 1e-7
#define MOD 1000000007
#define kbir 1000
#define pi 3.14159265359
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
bool visited[1000000];
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,k;
    sf2(n,k);
    multimap<int,int>m;
    vector<int>v(n);
    for (int i=0;i<n;i++)
    {
        sf(v[i]);
        m.insert({v[i],i+1});
    }
    sort(v.rbegin(),v.rend());
    v.resize(k);
    cout<<v[v.size()-1]<<endl;
    multimap<int,int>::iterator it;
    for (int i=0;i<v.size();i++)
    {
        int  cur=v[i];
        for (it=m.begin();it!=m.end();it++)
        {
            if (cur==it->first&&!visited[it->second])
            {
                cout<<it->second<<" ";
                visited[it->second]=1;
                break;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define sf(x) scanf("%d",&x)
#define sfd(x) scanf("%lf",&x)
#define sfbig(x) scanf("%I64d",&x)
#define sfbig2(x,y) scanf("%I64d%I64d",&x,&y)
#define pfbig(x) printf("%I64d\n",x)
#define sf2(x,y) scanf("%d%d",&x,&y)
#define sfc(x) scanf("%c",x)
#define pf(x) printf("%d\n",x);
#define EPS 1e-7
#define MOD 1000000007
#define kbir 1000
#define pi 3.14159265359
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
    int n,k;
    sf2(n,k);
    map<int,int>m;
    vector<int>v(n);
    for (int i=0;i<n;i++)
    {
        sf(v[i]);
        m[v[i]]=i+1;
    }
    sort(v.rbegin(),v.rend());
    v.resize(k);
    cout<<v[v.size()-1]<<endl;
    for (int i=0;i<k;i++)
        cout<<m[v[i]]<<" ";
    return 0;
}


#include <fstream>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

const int MAX = 1000;

int main()
{
	ifstream cin("input.txt");
	ofstream cout("output.txt");
	int n, k;
	P p[MAX];

	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> p[(p[i].second = i)].first;
	sort(p, p + n);
	cout << p[n-k].first << "\n";
	for (int i = n-k; i < n; i++)
		cout << (p[i].second + 1) << " ";
	cout << "\n";
}


#include <algorithm>
#include<fstream>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ll long long
#define rall(v) v.rbegin(), v.rend()
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define pii pair<int,int>
#define lb lower_bound
#define ub upper_bound
#include <cstdio>
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define PNL printf("\n")
#define pi(x) printf("%d\n",x)
pair < int,int > p[1003] ;
int main()
{
    ifstream cin("input.txt");
	ofstream cout("output.txt");
    int n , k , i , x ;

    si(n) ; si(k) ;
    for( i=1 ; i<=n ; i++)
    {
        cin >> x ;
       p[i] = {x,i} ;
    }
    sort( p+1 , p+n+1  ) ;

    for( i=n-k+1; i <= n ; i++)
        cout << p[i].se << " ";
    cout << endl;
    return 0 ;
}


#include<iostream>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ll long long
#define rall(v) v.rbegin(), v.rend()
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define pii pair<int,int>
#define lb lower_bound
#define ub upper_bound
#include <cstdio>
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define PNL printf("\n")
#define pi(x) printf("%d\n",x)
int main()
{
    int n , k  , i , x;
    vector< pii > v ;
    si(n) ; si(k) ;
    for( i=1 ; i<=n ; i++)
    {
        si(x) ;
        v.pb(mp(x,i));
    }
    sort( v.rbegin() , v.rend() ) ;
    for( i=0 ; i<k ; i++)
        cout << v[i].se << " ";
    cout << endl;
    return 0 ;
}


#include<iostream>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ll long long
#define rall(v) v.rbegin(), v.rend()
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define pii pair<int,int>
#define lb lower_bound
#define ub upper_bound
#include <cstdio>
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define PNL printf("\n")
#define pi(x) printf("%d\n",x)
int main()
{
    int n , k  , i , x;
    vector< pii > v ;
    si(n) ; si(k) ;
    for( i=1 ; i<=n ; i++)
    {
        si(x) ;
        v.pb( mp(x,i) );
    }
    sort( v.begin() , v.end() , greater<pii>() ) ;

    for( i=0 ; i<k ; i++)
        cout << v[i].se << " ";
    cout << endl;
    return 0 ;
}


#include<iostream>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include<fstream>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ll long long
#define rall(v) v.rbegin(), v.rend()
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define pii pair<int,int>
#define lb lower_bound
#define ub upper_bound
#include <cstdio>
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define PNL printf("\n")
#define pi(x) printf("%d\n",x)
pair < int,int > p[1003] ;
int main()
{
    ifstream cin("input.txt");
	ofstream cout("output.txt");
    int n , k , i , x ;

    si(n) ; si(k) ;
    for( i=1 ; i<=n ; i++)
    {
        cin >> x ;
       p[i] = {x,i} ;
    }
    sort( p+1 , p+n+1  ) ;
     cout << p[n-k+1].fi << endl;
    for( i=n-k+1; i <= n ; i++)
        cout << p[i].se << " ";
    cout << endl;
    return 0 ;
}


#include<iostream>
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include<fstream>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ll long long
#define rall(v) v.rbegin(), v.rend()
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define pii pair<int,int>
#define lb lower_bound
#define ub upper_bound
#include <cstdio>
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define PNL printf("\n")
#define pi(x) printf("%d\n",x)
pair < int,int > p[1003] ;
int main()
{
    ifstream cin("input.txt");
	ofstream cout("output.txt");
    int n , k , i , x ;
   // vector< pii > v ;
   // v.clear();
    si(n) ; si(k) ;
    for( i=1 ; i<=n ; i++)
    {
        cin >> x ;
       p[i] = {x,i} ;
    }
    sort( p+1 , p+n+1 , greater<pii>()  ) ;

    for( i=1 ; i <= k ; i++)
        cout << p[i].se << " ";
    cout << endl;
    return 0 ;
}


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

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);

    int n,k,z;
    cin>>n>>k;

    priority_queue<pair<int,int > > q;
    set<int > a;
    set<int >::iterator it;

    for(int i=0;i<n;i++)
    {
        cin>>z;
        q.push(make_pair(z,i+1));
    }

    for(int i=0;i<k-1;i++)
    {
        a.insert(q.top().second);
        q.pop();
    }

    a.insert(q.top().second);
    cout<<q.top().first<<endl;

    for(it=a.begin();it!=a.end();++it)
        cout<<*it<<" ";

    return 0;
}


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

int main()
{
    int n,k,z;
    cin>>n>>k;

    priority_queue<pair<int,int > > q;
    set<int > a;
    set<int >::iterator it;

    for(int i=0;i<n;i++)
    {
        cin>>z;
        q.push(make_pair(z,i+1));
    }

    for(int i=0;i<k-1;i++)
    {
        a.insert(q.top().second);
        q.pop();
    }

    a.insert(q.top().second);
    cout<<q.top().first<<endl;

    for(it=a.begin();it!=a.end();++it)
        cout<<*it<<" ";

    return 0;
}


int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);

    int n,k,z;
    cin>>n>>k;

    priority_queue<pair<int,int > > q;
    set<int > a;
    set<int >::iterator it;

    for(int i=0;i<n;i++)
    {
        cin>>z;
        q.push(make_pair(z,i+1));
    }

    for(int i=0;i<k-1;i++)
    {
        a.insert(q.top().second);
        q.pop();
    }

    a.insert(q.top().second);
    cout<<q.top().first<<endl;

    for(it=a.begin();it!=a.end();++it)
        cout<<*it<<" ";

    return 0;
}


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

bool compare(const pair<int,int>& first,const pair<int,int>& second)
{
    return first.first>second.first;
}

int main()
{
    int n,k,z;
    cin>>n>>k;

    vector <pair<int,int > > a;

    for(int i=0;i<n;i++)
    {
        cin>>z;
        a.push_back(make_pair(z,i));
    }

    sort(a.begin(),a.end(),compare);

    cout<<a[k-1].first<<endl;
    int i=k-1;
    while(i>=0)
    {
        cout<<a[i].second+1<<" ";
        i--;
    }

    return 0;
}


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

int main()
{
    int n,k,z;
    cin>>n>>k;

    priority_queue<pair<int,int > > q;
    set<int > a;
    set<int >::iterator it;

    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);

    for(int i=0;i<n;i++)
    {
        cin>>z;
        q.push(make_pair(z,i+1));
    }

    for(int i=0;i<k-1;i++)
    {
        a.insert(q.top().second);
        q.pop();
    }

    a.insert(q.top().second);
    cout<<q.top().first<<endl;

    for(it=a.begin();it!=a.end();++it)
        cout<<*it<<" ";

    return 0;
}


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

bool compare(const pair<int,int>& first,const pair<int,int>& second)
{
    return first.first>second.first;
}

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);

    int n,k,z;
    cin>>n>>k;

    vector <pair<int,int > > a;

    for(int i=0;i<n;i++)
    {
        cin>>z;
        a.push_back(make_pair(z,i));
    }

    sort(a.begin(),a.end(),compare);

    cout<<a[k-1].first<<endl;
    int i=k-1;
    while(i>=0)
    {
        cout<<a[i].second+1<<" ";
        i--;
    }

    return 0;
}


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

bool compare(const pair<int,int>& first,const pair<int,int>& second)
{
    return first.first>second.first;
}

int main()
{
    int n,k,z;
    cin>>n>>k;

    vector <pair<int,int > > a;
    vector <pair<int,int > >::iterator it;

    for(int i=0;i<n;i++)
    {
        cin>>z;
        a.push_back(make_pair(z,i));
    }

    sort(a.begin(),a.end(),compare);

    cout<<a[k-1].first<<endl;
    int i=k-1;
    while(i>=0)
    {
        cout<<a[i].second+1<<" ";
        i--;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define PB push_back

#define FOR(prom,a,b) for( ll prom = (a); prom < (ll)(b); ++prom )
#define F(a) FOR(i,0,a)
#define FF(a) FOR(j,0,a)

#define EPS (1e-10)
#define INF ((1LL<<62LL)-1LL)

bool cmp(const pair<ll, ll> &a, const pair<ll, ll> & b ){
	return a.first>b.first;

}
int main(){

freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
	ll N, K, X;
	cin>>N>>K;
	vii v;
	F(N){
		cin>>X;
		v.PB(make_pair(X, i+1));
	}
	sort(v.begin(), v.end(), cmp);
	cout<<v[K-1].first<<endl;
	F(K){
		cout<<v[i].second<<" ";
	}
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define PB push_back

#define FOR(prom,a,b) for( ll prom = (a); prom < (ll)(b); ++prom )
#define F(a) FOR(i,0,a)
#define FF(a) FOR(j,0,a)

#define EPS (1e-10)
#define INF ((1LL<<62LL)-1LL)

#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

bool cmp(const pair<ll, ll> &a, const pair<ll, ll> & b ){
	return a.first>b.first;

}
int main(){
	ll N, K, X;
	cin>>N>>K;
	vii v;
	F(N){
		cin>>X;
		v.PB(make_pair(X, i+1));
	}
	sort(v.begin(), v.end(), cmp);
	cout<<v[K-1].first<<endl;
	F(K){
		cout<<v[i].second<<" ";
	}
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define PB push_back

#define FOR(prom,a,b) for( ll prom = (a); prom < (ll)(b); ++prom )
#define F(a) FOR(i,0,a)
#define FF(a) FOR(j,0,a)

#define EPS (1e-10)
#define INF ((1LL<<62LL)-1LL)

#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

bool cmp(const pair<ll, ll> &a, const pair<ll, ll> & b ){
	return a.first>b.first;

}
int main(){
	ll N, K, X;
	cin>>N>>K;
	vii v;
	F(N){
		cin>>X;
		v.PB(make_pair(X, i+1));
	}
	sort(v.begin(), v.end(), cmp);
	F(K){
		cout<<v[i].second<<" ";
	}
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define PB push_back

#define FOR(prom,a,b) for( ll prom = (a); prom < (ll)(b); ++prom )
#define F(a) FOR(i,0,a)
#define FF(a) FOR(j,0,a)

#define EPS (1e-10)
#define INF ((1LL<<62LL)-1LL)

#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

bool cmp(const pair<int, int> &a, const pair<int, int> & b ){
	return a.first>b.first;

}
int main(){
	ll N, K, X;
	cin>>N>>K;
	vii v;
	F(N){
		cin>>X;
		v.PB(make_pair(X, i+1));
	}
	sort(v.begin(), v.end(), cmp);
	F(K){
		cout<<v[i].second<<" ";
	}
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define PB push_back

#define FOR(prom,a,b) for( ll prom = (a); prom < (ll)(b); ++prom )
#define F(a) FOR(i,0,a)
#define FF(a) FOR(j,0,a)

#define EPS (1e-10)
#define INF ((1LL<<62LL)-1LL)

bool cmp(const pair<ll, ll> &a, const pair<ll, ll> & b ){
	return a.first>b.first;

}
int main(){
	ll N, K, X;
	cin>>N>>K;
	vii v;
	F(N){
		cin>>X;
		v.PB(make_pair(X, i+1));
	}
	sort(v.begin(), v.end(), cmp);
	cout<<v[K-1].first<<endl;
	F(K){
		cout<<v[i].second<<" ";
	}
	cout<<endl;
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <array>
#include<string.h>
#include<algorithm>
using namespace std;

vector<int>vec;

int main()
{
	int n , k ;
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> k;
	int arr[n];
	int narr[n];
	for(int i = 0 ; i < n ; i++)
		{
			cin >> arr[i];
			narr[i] = arr[i];
		}
	sort(arr,arr+n);
	int cnt = 0;
	for(int i = n-1 ; i >=0; i--)
	{
		if(cnt == k)
			break;
		else
		{
			vec.push_back(arr[i]);
			cnt++;
		}
	}

	sort(vec.begin(),vec.begin()+vec.size());

	cout<<vec[0]<<endl;
	for(int i = 0 ; i < n ; i++)
	{
		if(find(vec.begin(), vec.end(), narr[i]) != vec.end())
			cout<<i+1<<" ";
	}

}


#include <iostream>
#include <map>
#include <vector>
#include <array>
#include<string.h>
#include<algorithm>
using namespace std;

vector<int>vec;

bool find(int a)
{
	for(int i = 0 ; i < vec.size();i++)
		if(vec[i] == a)
			return true;
	return false;
}

int main()
{
	int n , k ;
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> k;
	int arr[n];
	int narr[n];
	for(int i = 0 ; i < n ; i++)
		{
			cin >> arr[i];
			narr[i] = arr[i];
		}

	sort(arr,arr+n);

	int cnt = 0;
	for(int i = n-1 ; i >=0; i--)
	{
		if(cnt == k)
			break;
		else
		{
			vec.push_back(arr[i]);
			cnt++;
		}
	}
	sort(vec.begin(),vec.begin()+vec.size());

	cout<<vec[0]<<endl;
	int cont = 0;
	for(int i = 0 ; i < n ; i++)
	{
		if(cont == k)
			break;
		else
		{
			if(find(narr[i]))
						cout<<i+1<<" ";
			cont++;
		}

	}
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <array>
#include<string.h>
#include<algorithm>
using namespace std;

vector<int>vec;

bool find(int a)
{
	for(int i = 0 ; i < vec.size();i++)
		if(vec[i] == a)
			return true;
	return false;
}

int main()
{
	int n , k ;
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	cin >> n >> k;
	int arr[n];
	int narr[n];
	for(int i = 0 ; i < n ; i++)
		{
			cin >> arr[i];
			narr[i] = arr[i];
		}

	sort(arr,arr+n);

	int cnt = 0;
	for(int i = n-1 ; i >=0; i--)
	{
		if(cnt == k)
			break;
		else
		{
			vec.push_back(arr[i]);
			cnt++;
		}
	}
	sort(vec.begin(),vec.begin()+vec.size());

	cout<<vec[0]<<endl;
	int cont = 0;
	for(int i = 0 ; i < n ; i++)
	{
		if(cont == k)
			break;
		else
		{
			if(find(narr[i]))
						cout<<i+1<<" ";
			cont++;
		}

	}
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <array>
#include<string.h>
#include<algorithm>
using namespace std;

vector<int>vec;

bool find(int a)
{
	for(int i = 0 ; i < vec.size();i++)
		if(vec[i] == a)
			return true;
	return false;
}

int main()
{
	int n , k ;
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n >> k;
	int arr[n];
	int narr[n];
	for(int i = 0 ; i < n ; i++)
		{
			cin >> arr[i];
			narr[i] = arr[i];
		}

	sort(arr,arr+n);

	int cnt = 0;
	for(int i = n-1 ; i >=0; i--)
	{
		if(cnt == k)
			break;
		else
		{
			vec.push_back(arr[i]);
			cnt++;
		}
	}
	sort(vec.begin(),vec.begin()+vec.size());

	cout<<vec[0]<<endl;
	int cont = 0;
	for(int i = 0 ; i < n ; i++)
	{
		if(cont == k)
			break;
		else
		{
			if(find(narr[i]))
			{
				cout<<i+1<<" ";
	cont++;

			}
		}

	}
	return 0;
}


#include<iostream>
#include<map>
#include<deque>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    map<int, deque<int> > mappy;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        mappy[tmp].push_back(i);
    }
    bool ref[n] = {false};
    int cnt = 0;
    map<int, deque<int> >::iterator itr1 = mappy.end();
    itr1--;
    while(cnt < k){
        deque<int>::iterator itr2 = itr1->second.begin();
        while(itr2 != itr1->second.end()){
            ref[*itr2] = true;
            itr2++;
        }
        cnt += itr1->second.size();
        if(cnt >= k)
            cout << itr1->first << endl;
        itr1--;
    }
    cnt = 0;
    for(int i = 0; i < n && cnt < k; i++)
        if(ref[i]){
            cout << i + 1 << " ";
            k++;
        }

    return 0;
}


#include<iostream>
#include<map>
#include<set>
#include<deque>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    map<int, deque<int> > mappy;
    for(int i = 0; i < n; i++){
        int val;
        cin >> val;
        mappy[val].push_back(i + 1);
    }
    int cnt = 0;
    map<int, deque<int> > :: iterator itr1 = mappy.end();
    itr1--;
    set<int> ans;
    while(cnt < k){
        deque<int> que = itr1->second;
        cnt += itr1->second.size();
        if(cnt >= k)
            cout << itr1->first << endl;
        itr1--;
        while(que.empty() == false){
            ans.insert(que.front());
            que.pop_front();
        }
    }
    set<int> :: iterator itr3 = ans.begin();
    cnt = 0;
    while(cnt < k){
        cout << *itr3 << " ";
        itr3++;
        cnt++;
    }
    return 0;
}


#include<iostream>
#include<map>
#include<set>
#include<deque>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    map<int, deque<int> > mappy;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        mappy[tmp].push_back(i + 1);
    }

    int cnt = 0;
    map<int, deque<int> > :: iterator itr1 = mappy.end();
    itr1--;
    set<int> ans;
    while(cnt < k){
        deque<int> que = itr1->second;
        cnt += itr1->second.size();
        if(cnt >= k)
            cout << itr1->first << endl;
        itr1--;
        while(que.empty() == false){
            ans.insert(que.front());
            que.pop_front();
        }
    }
    set<int> :: iterator itr3 = ans.begin();
    cnt = 0;
    while(cnt < k){
        cout << *itr3 << " ";
        itr3++;
        cnt++;
    }
    return 0;
}


#include<iostream>
#include<map>
#include<set>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    map<int, set<int> > mappy;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        mappy[tmp].insert(i + 1);
    }
    map<int, set<int> > :: iterator itr = mappy.end();
    itr--;
    set<int> hours;
    do{
        static int cnt = 0;
        cnt += itr->second.size();
        set<int> :: iterator itr2 = itr->second.begin();
        while(itr2 != itr->second.end()){
            hours.insert(*itr2);
            itr2++;
        }
        if(cnt >= k){
            cout << itr->first << endl;
            break;
        }
        itr--;
    }while(itr != mappy.begin());

    int f = 0;
    set<int> :: iterator itrFin = hours.begin();
    while(f < k){
        cout << *itrFin << " ";
        itrFin++;
        f++;
    }
    return 0;
}


#include<iostream>
#include<map>
#include<deque>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    map<int, deque<int> > mappy;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        mappy[tmp].push_back(i);
    }
    bool ref[n] = {false};
    int cnt = 0;
    map<int, deque<int> >::iterator itr1 = mappy.end();
    itr1--;
    while(cnt < k){
        cout << "Cnt: " << cnt;
        deque<int>::iterator itr2 = itr1->second.begin();
        while(itr2 != itr1->second.end()){
            cout << " Val: " << *itr2;
            ref[*itr2] = true;
            itr2++;
        }
        cnt += itr1->second.size();
        if(cnt >= k)
            cout << itr1->first << endl;
        itr1--;
    }
    cout << "\nOUT OF LOOP 1\n";
    cnt = 0;
    for(int i = 0; i < n && cnt < k; i++)
        if(ref[i]){
            cout << i + 1 << " ";
            cnt++;
        }
    cout << "\nOUT OF LOOP 2";
    cnt = 0;
    return 0;
}


#include<iostream>
#include<map>
#include<set>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    map<int, set<int> > mappy;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        mappy[tmp].insert(i + 1);
    }
    map<int, set<int> > :: iterator itr = mappy.end();
    itr--;
    set<int> hours;
    int cnt = 0;
    while(1){
        cnt += (itr->second).size();
        set<int> :: iterator itr2 = (itr->second).begin();
        while(itr2 != (itr->second).end()){
            hours.insert(*itr2);
            itr2++;
        }
        if(cnt >= k){
            cout << itr->first << endl;
            break;
        }
        if(itr == mappy.begin())
            break;
        itr--;
    }

    int f = 0;
    set<int> :: iterator itrFin = hours.begin();
    while(f < k){
        cout << *itrFin << " ";
        itrFin++;
        f++;
    }
    return 0;
}


#include<iostream>
#include<map>
#include<deque>

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    map<int, deque<int> > mappy;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        mappy[tmp].push_back(i);
    }
    bool ref[n] = {false};
    int cnt = 0;
    map<int, deque<int> >::iterator itr1 = mappy.end();
    itr1--;
    while(cnt < k){
        deque<int>::iterator itr2 = itr1->second.begin();
        while(itr2 != itr1->second.end()){
            ref[*itr2] = true;
            itr2++;
        }
        cnt += itr1->second.size();
        if(cnt >= k)
            cout << itr1->first << endl;
        itr1--;
    }
    cnt = 0;
    for(int i = 0; i < n && cnt < k; i++)
        if(ref[i]){
            cout << i + 1 << " ";
            cnt++;
        }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<map>
#include<deque>

using namespace std;

int main(){
    FILE *inputFile, *outputFile;
    inputFile = fopen("input.txt", "r");
    outputFile = fopen("output.txt", "w");
    int n, k;
    fscanf(inputFile, "%d %d", &n, &k);
    map<int, deque<int> > mappy;
    for(int i = 0; i < n; i++){
        int tmp;
        fscanf(inputFile, "%d", &tmp);
        mappy[tmp].push_back(i);
    }
    bool ref[n] = {false};
    int cnt = 0;
    map<int, deque<int> >::iterator itr1 = mappy.end();
    itr1--;
    while(cnt < k){
        deque<int>::iterator itr2 = itr1->second.begin();
        while(itr2 != itr1->second.end()){
            ref[*itr2] = true;
            itr2++;
        }
        cnt += itr1->second.size();
        if(cnt >= k)
            fprintf(outputFile, "%d\n", itr1->first);
        itr1--;
    }
    cnt = 0;
    for(int i = 0; i < n && cnt < k; i++)
        if(ref[i]){
            fprintf(outputFile, "%d ", i + 1);
            cnt++;
        }
    return 0;
}


//#include <bits/stdc++.h>
#include <stdlib.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>
#include<stdio.h>
#include<map>
#include<set>
#include<vector>
#include<bitset>
#define  PI 3.1415926536
using namespace std;

int n;
vector<pair<int, int>>my;

void __sort()
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (my[i].first>my[j].first)swap(my[i], my[j]);
		}
	}
}
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n, k;
	for (int i = 0; i < n; i++)
	{
		int x; cin >> x;
		my.push_back(make_pair(x, i + 1));
	}
	__sort();
	int j = n - 1;
	int mm = 0;
	vector<int>res;
	for (int i = 0; i < k; i++)
	{
		res.push_back(my[j].second);
		j--;
		mm = my[j].first;
	}
	sort(res.begin(), res.begin() + k);
	cout << mm << endl;
	for (int i = 0; i < k; i++)
	{
		cout << res[i] << " ";
	}
	cout << endl;
	return 0;

}


//#include <bits/stdc++.h>
#include <stdlib.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>
#include<stdio.h>
#include<map>
#include<set>
#include<vector>
#include<bitset>
#define  PI 3.1415926536
using namespace std;

int n;
vector<pair<int, int>>my;

void __sort()
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (my[i].first>my[j].first)swap(my[i], my[j]);
		}
	}
}
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n, k;
	for (int i = 0; i < n; i++)
	{
		int x; cin >> x;
		my.push_back(make_pair(x, i + 1));
	}
	__sort();
	int j = n - 1;
	int mm = 0;
	vector<int>res;
	for (int i = 0; i < k; i++)
	{
		res.push_back(my[j].second);
		j--;
		mm = my[j].first;
	}
	sort(my.begin(), my.begin() + k);
	cout << mm << endl;
	for (int i = 0; i < k; i++)
	{
		cout << res[i] << " ";
	}
	cout << endl;
	return 0;

}


//#include <bits/stdc++.h>
#include <stdlib.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>
#include<stdio.h>
#include<map>
#include<set>
#include<vector>
#include<bitset>
#define  PI 3.1415926536
using namespace std;

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n, k;
	map<int, int>mymap;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		mymap.insert(make_pair(x, i + 1));
	}
	map<int, int>::iterator it = mymap.end();
	set<int>res;
	int mm = 0;
	it--;
	while (k--)
	{
		res.insert(it->second);
		mm = it->first;
		it--;
	}
	cout << mm << endl;
	set<int>::iterator ii = res.begin();
	for (; ii != res.end(); ii++)cout << *ii << " ";
	cout << endl;
	return 0;

}


//#include <bits/stdc++.h>
#include <stdlib.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>
#include<stdio.h>
#include<map>
#include<set>
#include<vector>
#include<bitset>
#define  PI 3.1415926536
using namespace std;

int n;
vector<pair<int, int>>my;

void __sort()
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (my[i].first>my[j].first)swap(my[i], my[j]);
		}
	}
}
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int x; cin >> x;
		my.push_back(make_pair(x, i + 1));
	}
	__sort();
	int mm = 0;
	vector<int>res;
	for (int i = 0; i < k; i++)
	{
		res.push_back(my[i].second);
		mm = my[i].first;
	}
	sort(res.begin(), res.begin() + k);
	cout << mm << endl;
	for (int i = 0; i < k; i++)
	{
		cout << res[i] << " ";
	}
	cout << endl;
	return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 1e3 + 100;

pair<int, int> arr[MAXN];

int main()
{
  std::ios::sync_with_stdio(false);

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i].first;
		arr[i].second = i;
	}
	sort(arr, arr + n, greater<pair<int, int> >());
	cout << arr[k].first << "\n";
	for (int i = 1; i <= k; ++i) {
		if (i != 1) cout << " " << "\n";
		cout << arr[i].second;
	}
	return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 1e3 + 100;

pair<int, int> arr[MAXN];

int main()
{
  std::ios::sync_with_stdio(false);

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i].first;
		// trace2(i, arr[i].first);
		arr[i].second = i;
	}
	sort(arr + 1, arr + n + 1, greater<pair<int, int> >());
	cout << arr[k].first << "\n";
	for (int i = 1; i <= k; ++i) {
		// trace3(i, arr[i].first, arr[i].second);
		if (i != 1) cout << " ";
		cout << arr[i].second;
	}
	return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 1e3 + 100;

pair<int, int> arr[MAXN];

int main()
{
  std::ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i].first;
		arr[i].second = i;
	}
	sort(arr, arr + n, greater<pair<int, int> >());
	cout << arr[k].first;
	for (int i = 1; i <= k; ++i) {
		cout << arr[i].second;
	}
	return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 1e3 + 100;

pair<int, int> arr[MAXN];

int main()
{
  std::ios::sync_with_stdio(false);

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i].first;
		arr[i].second = i;
	}
	sort(arr, arr + n, greater<pair<int, int> >());
	cout << arr[k].first;
	for (int i = 1; i <= k; ++i) {
		if (i != 1) cout << " " << "\n";
		cout << arr[i].second;
	}
	return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include <bits/stdc++.h>

using namespace std;

#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << endl;
#define trace4(x, y, z, a) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << " " << #a << ": " << a << endl;

typedef long long lolo;
typedef unsigned long long ulolo;

const int MAXN = 1e3 + 100;

pair<int, int> arr[MAXN];

int main()
{
  std::ios::sync_with_stdio(false);

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i].first;
		arr[i].second = i;
	}
	sort(arr, arr + n, greater<pair<int, int> >());
	cout << arr[k].first;
	for (int i = 1; i <= k; ++i) {
		cout << arr[i].second;
	}
	return 0;
}

// g++ -W -Wall -Wextra -pedantic -std=c++0x -o p main.cpp


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld ",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define nl printf("\n");
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    int2(n,k);

    vector<pair<int, int>> vec;

    for_start(i,n){
        int t;
        int1(t);
        vec.pb(mp(t,i));
    }
    sort(vec.bg, vec.ed);

    pint(vec[n-k].first);
    nl;
    for_val(i,n-k,n)
        pint(vec[i].second+1);

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int search(vi & vec,int num){
    for_start(i,vec.size()){
        if(vec[i]==num){
            return i;
        }
    }
}
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        int t = search(org,tempv[i]);
        org[t] = -1;
        pint(++t);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)

typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int search(vi & vec,int num){
    for_start(i,vec.size()){
        if(vec[i]==num){
            return i;
        }
    }
}
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        int t = search(org,tempv[i]);
        org[t] = -1;
        pint(++t);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        vi:: iterator f = find(org.begin(),org.end(),tempv[i]);
        int t = f-org.begin();
        org[t] = -1;
        arr.pb(++t);
    }
    sort(arr.begin(),arr.end());
    for_start(i,arr.size()){
         pint(arr[i]);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)

typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int search(vi & vec,int num){
    for_start(i,vec.size()){
        if(vec[i]==num){
            return i;
        }
    }
}
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #else
    // online submission
    #endif*/
    #ifdef kn
      freopen("inp.txt","r",stdin) ;
      freopen("out.txt","w",stdout) ;
     #endif

    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        int t = search(org,tempv[i]);
        org[t] = -1;
        pint(++t);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)

typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int search(vi & vec,int num){
    for_start(i,vec.size()){
        if(vec[i]==num){
            return i;
        }
    }
}
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #else
    // online submission
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        int t = search(org,tempv[i]);
        org[t] = -1;
        pint(++t);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)

typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int search(vi & vec,int num){
    for_start(i,vec.size()){
        if(vec[i]==num){
            return i;
        }
    }
}
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #else
    // online submission

    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        int t = search(org,tempv[i]);
        org[t] = -1;
        pint(++t);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)

typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int search(vi & vec,int num){
    for_start(i,vec.size()){
        if(vec[i]==num){
            return i;
        }
    }
}
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #else
    // online submission
    #endif

    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        int t = search(org,tempv[i]);
        org[t] = -1;
        pint(++t);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)

typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int search(vi & vec,int num){
    for_start(i,vec.size()){
        if(vec[i]==num){
            return i;
        }
    }
}
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);

    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        int t = search(org,tempv[i]);
        org[t] = -1;
        pint(++t);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        vi:: iterator f = find(org.begin(),org.end(),tempv[i]);
        int t = f-org.begin();
        org[t] = -1;
        pint(++t);
    }
  //  sort(arr.begin(),arr.
    //for_start(i,arr.size()){
      //   pint(arr[i]);
    //}
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
#define pint(x) printf("%d ",x)
#define plint(x) printf("%lld\n",x)
//#define sort(a,n) qsort(a,n,sizeof(int),cmpfunc)
#define pb push_back
#define for_start(i,n) for(int i=0; i<n; i++)
#define for_end(i,n) for(int i=n-1; i>=0; i--)
#define for_val(i,a,n) for(int i=a; i<n; i++)
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
const int INF = 0x3f3f3f3f;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

//int findf()

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    int2(n,k);
    vi org,tempv;
    for_start(i,n){
        int a;
        int1(a);
        org.pb(a);
    }
    tempv = org;
    sort(tempv.begin(),tempv.end());

    pint(tempv[n-k]);

    printf("\n");
    vi arr;
    for_val(i,n-k,n){
        vi:: iterator f = find(org.begin(),org.end(),tempv[i]);
        int t = f-org.begin();
        org[t] = -1;
        arr.pb(++t);
    }
    for_start(i,arr.size()){
         pint(arr[i]);
    }
    return 0;
}


#include <iostream>
using namespace std;

void sort(int num[], int low, int high, int m){
	int i, j, k;
	int size1 = m - low + 1;
	int size2 = high - m;
	int a[size1], b[size2];
	for(i = 0; i < size1; i++) a[i] = num[low+i];
	for(j = 0; j < size2; j++) b[j] = num[m+1+j];
	i = 0, j = 0, k = low;
	while(i < size1 and j < size2){
		if(a[i] <= b[j]){
			num[k] = a[i];
			i++, k++;
		}else{
			num[k] = b[j];
			k++, j++;
		}
	}
	while(i < size1){
		num[k] = a[i];
		i++, k++;
	}
	while(j < size2){
		num[k] = b[j];
		j++, k++;
	}
}

void merge(int num[], int low, int high){
	if(low < high){
		int m = (low + high)/2;
		merge(num,low,m);
		merge(num,m+1,high);
		sort(num,low,high,m);
	}
}

void solve(){
	int n, k;
	cin>>n;
	cin>>k;
	int num[n];
	int aux[n];
	for(int i = 0; i < n; i++){
		cin>>num[i];
		aux[i] = num[i];
	}
	merge(aux,0,n-1);
	int i = n - 1;
	int fin[k];
	while(k -- > 0){
		for(int j = 0; j < n; j++){
			if(num[j] == aux[i]){
				fin[k]=j + 1;
				if(k!=0) num[j]=-1;
				break;
			}
		}
		i--;
	}
	cout<<num[fin[0]-1]<<endl;
	for(auto &x: fin) cout<<x<<" ";
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int t = 1;
	while(t -- > 0)	solve();
	return 0;
}


#include <iostream>
using namespace std;

void sort(int num[], int low, int high, int m){
	int i, j, k;
	int size1 = m - low + 1;
	int size2 = high - m;
	int a[size1], b[size2];
	for(i = 0; i < size1; i++) a[i] = num[low+i];
	for(j = 0; j < size2; j++) b[j] = num[m+1+j];
	i = 0, j = 0, k = low;
	while(i < size1 and j < size2){
		if(a[i] <= b[j]){
			num[k] = a[i];
			i++, k++;
		}else{
			num[k] = b[j];
			k++, j++;
		}
	}
	while(i < size1){
		num[k] = a[i];
		i++, k++;
	}
	while(j < size2){
		num[k] = b[j];
		j++, k++;
	}
}

void merge(int num[], int low, int high){
	if(low < high){
		int m = (low + high)/2;
		merge(num,low,m);
		merge(num,m+1,high);
		sort(num,low,high,m);
	}
}

void solve(){
	int n, k;
	cin>>n;
	cin>>k;
	int num[n];
	int aux[n];
	for(int i = 0; i < n; i++){
		cin>>num[i];
		aux[i] = num[i];
	}
	merge(aux,0,n-1);
	int i = n - 1;
	int fin[k];
	while(k -- > 0){
		for(int j = 0; j < n; j++){
			if(num[j] == aux[i]){
				fin[k]=j + 1;
				if(k!=0) num[j]=-1;
				break;
			}
		}
		i--;
	}
	cout<<num[fin[0]-1]<<endl;
	for(auto &x: fin) cout<<x<<" ";
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;
	cin>>t;
	while(t -- > 0) solve();
	return 0;
}


#include <iostream>
using namespace std;

void sort(int num[], int low, int high, int m){
	int i, j, l;
	int size1 = m - low + 1;
	int size2 = high - m;
	int a[size1], b[size2];
	for(i = 0; i < size1; i++) a[i] = num[low+i];
	for(j = 0; j < size2; j++) b[j] = num[m+1+j];
	i = 0, j = 0, l = low;
	while(i < size1 and j < size2){
		if(a[i] <= b[j]){
			num[l] = a[i];
			i++, l++;
		}else{
			num[l] = b[j];
			l++, j++;
		}
	}
	while(i < size1){
		num[l] = a[i];
		i++, l++;
	}
	while(j < size2){
		num[l] = b[j];
		i++, l++;
	}
}

void merge(int num[], int low, int high){
	if(low < high){
		int m = (low + high)/2;
		merge(num,low,m);
		merge(num,m+1,high);
		sort(num,low,high,m);
	}
}

void solve(){
	int n, k;
	cin>>n;
	cin>>k;
	int num[n];
	int aux[n];
	for(int i = 0; i < n; i++){
		cin>>num[i];
		aux[i] = num[i];
	}
	merge(aux,0,n-1);
	int i = n - 1;
	int fin[k];
	while(k -- > 0){
		for(int j = 0; j < n; j++){
			if(num[j] == aux[i]){
				fin[k]=j + 1;
				if(k!=0) num[j]=-1;
				break;
			}
		}
		i--;
	}
	cout<<num[fin[0]-1]<<endl;
	for(auto &x: fin) cout<<x<<" ";
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int t = 1;
	cin>>t;
	while(t -- > 0) solve();

	return 0;
}


#include <iostream>
using namespace std;

void sort(int num[], int low, int high, int m){
	int i, j, l;
	int size1 = m - low + 1;
	int size2 = high - m;
	int a[size1], b[size2];
	for(i = 0; i < size1; i++) a[i] = num[low+i];
	for(j = 0; j < size2; j++) b[j] = num[m+1+j];
	i = 0, j = 0, l = low;
	while(i < size1 and j < size2){
		if(a[i] <= b[j]){
			num[l] = a[i];
			i++, l++;
		}else{
			num[l] = b[j];
			l++, j++;
		}
	}
	while(i < size1){
		num[l] = a[i];
		i++, l++;
	}
	while(j < size2){
		num[l] = b[j];
		i++, l++;
	}
}

void merge(int num[], int low, int high){
	if(low < high){
		int m = (low + high)/2;
		merge(num,low,m);
		merge(num,m+1,high);
		sort(num,low,high,m);
	}
}

void solve(){
	int n, k;
	cin>>n;
	cin>>k;
	int num[n];
	int aux[n];
	for(int i = 0; i < n; i++){
		cin>>num[i];
		aux[i] = num[i];
	}
	merge(aux,0,n-1);
	int i = n - 1;
	int fin[k];
	while{k -- > 0}{
		for(int j = 0; j < n; j++){
			if(num[j] == aux[i]){
				fin[k]=j + 1;
				if(k!=0) num[j]=-1;
				break;
			}
		}
		i--;
	}
	cout<<num[fin[0]-1]<<endl;
	for(auto &: fin) cout<<x<<" ";
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int t = 1;
	cin>>t;
	while(t -- > 0) solve();

	return 0;
}


#include <iostream>
using namespace std;

void sort(int num[], int low, int high, int m){
	int i, j, k;
	int size1 = m - low + 1;
	int size2 = high - m;
	int a[size1], b[size2];
	for(i = 0; i < size1; i++) a[i] = num[low+i];
	for(j = 0; j < size2; j++) b[j] = num[m+1+j];
	i = 0, j = 0, k = low;
	while(i < size1 and j < size2){
		if(a[i] <= b[j]){
			num[k] = a[i];
			i++, k++;
		}else{
			num[k] = b[j];
			k++, j++;
		}
	}
	while(i < size1){
		num[k] = a[i];
		i++, k++;
	}
	while(j < size2){
		num[k] = b[j];
		j++, k++;
	}
}

void merge(int num[], int low, int high){
	if(low < high){
		int m = (low + high)/2;
		merge(num,low,m);
		merge(num,m+1,high);
		sort(num,low,high,m);
	}
}

void solve(){
	int n, k;
	cin>>n;
	cin>>k;
	int num[n];
	int aux[n];
	for(int i = 0; i < n; i++){
		cin>>num[i];
		aux[i] = num[i];
	}
	merge(aux,0,n-1);
	int i = n - 1;
	int fin[k];
	while(k -- > 0){
		for(int j = 0; j < n; j++){
			if(num[j] == aux[i]){
				fin[k]=j + 1;
				if(k!=0) num[j]=-1;
				break;
			}
		}
		i--;
	}
	cout<<num[fin[0]-1]<<endl;
	for(auto &x: fin) cout<<x<<" ";
}

int main(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int t = 1;
	cin>>t;
	while(t -- > 0) solve();

	return 0;
}


#include<bits/stdc++.h>
#define lp(i,n) for (int i=0;i<n;i++)
#define ef else if
#define re return
#define ll long long
#define oo 2000000000
using namespace std;
int n,m,k,a[1001],b[1001];
vector<int>v;
int main()
{
    cin>>n>>k;
    for (int i=0;i<n;++i)cin>>a[i],b[i]=a[i];
    sort(a,a+n);
    reverse(a,a+n);
   cout<<a[k-1]<<endl;
    for (int i=0;i<n&&k;++i,k--){
        for (int j =0;j<n;++j){
            if (a[i]==b[j]){
                v.push_back(j+1);
                break ;
            }
        }
    }
    sort(v.begin(),v.end());
    for (auto i : v)cout<<i<<" ";
    re 0;

}
/*

*/
/*

*/


#include<bits/stdc++.h>
#define lp(i,n) for (int i=0;i<n;i++)
#define ef else if
#define re return
#define ll long long
#define oo 2000000000
using namespace std;
int n,m,k,a[1001],b[1001];
vector<int>v;
int main()
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);

    cin>>n>>k;
    for (int i=0;i<n;++i)cin>>a[i],b[i]=a[i];
    sort(a,a+n);
    reverse(a,a+n);
   cout<<a[k-1]<<endl;
    for (int i=0;i<n&&k;++i,k--){
        for (int j =0;j<n;++j){
            if (a[i]==b[j]){
                v.push_back(j+1);
                break ;
            }
        }
    }
    sort(v.begin(),v.end());
    for (auto i : v)cout<<i<<" ";
    re 0;

}
/*

*/
/*

*/


#include<bits/stdc++.h>
#define lp(i,n) for (int i=0;i<n;i++)
#define ef else if
#define re return
#define ll long long
#define oo 2000000000
using namespace std;
int n,m,k,a[1001],b[1001];
vector<int>v;
int main()
{
        freopen("input.txt","r",stdin);

    cin>>n>>k;
    for (int i=0;i<n;++i)cin>>a[i],b[i]=a[i];
    sort(a,a+n);
    reverse(a,a+n);
   cout<<a[k-1]<<endl;
    for (int i=0;i<n&&k;++i,k--){
        for (int j =0;j<n;++j){
            if (a[i]==b[j]){
                v.push_back(j+1);
                break ;
            }
        }
    }
    sort(v.begin(),v.end());
    for (auto i : v)cout<<i<<" ";
    re 0;

}
/*

*/
/*

*/


#include<bits/stdc++.h>
#define lp(i,n) for (int i=0;i<n;i++)
#define ef else if
#define re return
#define ll long long
#define oo 2000000000
using namespace std;
int n,m,k,a[1001],b[1001];
vector<int>v;
pair<int,int>p[1000];
int main()
{
         freopen("input.txt","r",stdin);
         freopen("output.txt","w",stdout);

    cin>>n>>k;
    for (int i=0;i<n;++i)cin>>a[i],p[i].first=a[i],p[i].second=i+1;
    sort(a,a+n);
    reverse(a,a+n);
    sort(p,p+n);
    reverse(p,p+n);
   cout<<a[k-1]<<endl;
    for (int i=0;i<k;++i){
    v.push_back(p[i].second);
    }
    sort(v.begin(),v.end());
    for (auto i : v)cout<<i<<" ";
    re 0;

}
/*

*/
/*

*/


#include<bits/stdc++.h>
using namespace std;
int main()
{
	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	int n,k,a[10000],id[10000],az[10000];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		id[i]=i;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[i]<a[j])
			{
				swap(a[i],a[j]);
				swap(id[i],id[j]);
			}
		}
	}
	cout<<a[k]<<endl;
	for(int i=1;i<=k;i++)
	az[i]=id[i];
	sort(az+1,az+k+1);
	for(int i=1;i<=k;i++)
	cout<<id[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,a[10000],id[10000],az[10000];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		id[i]=i;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[i]<a[j])
			{
				swap(a[i],a[j]);
				swap(id[i],id[j]);
			}
		}
	}
	cout<<a[k]<<endl;
	for(int i=1;i<=k;i++)
	az[i]=id[i];
	sort(az+1,az+k+1);
	for(int i=1;i<=k;i++)
	cout<<az[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	int n,k,a[10000],id[10000],az[10000];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		id[i]=i;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[i]<a[j])
			{
				swap(a[i],a[j]);
				swap(id[i],id[j]);
			}
		}
	}
	cout<<a[k]<<endl;
	for(int i=1;i<=k;i++)
	cout<<id[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,a[10000],id[10000];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		id[i]=i;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[i]<a[j])
			{
				swap(a[i],a[j]);
				swap(id[i],id[j]);
			}
		}
	}
	cout<<a[k]<<endl;
	for(int i=1;i<=k;i++)
	cout<<id[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	int n,k,a[10000],id[10000],az[10000];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		id[i]=i;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[i]<a[j])
			{
				swap(a[i],a[j]);
				swap(id[i],id[j]);
			}
		}
	}
	cout<<a[k]<<endl;
	for(int i=1;i<=k;i++)
	az[i]=id[i];
	sort(az+1,az+k+1);
	for(int i=1;i<=k;i++)
	cout<<az[i]<<" ";
}


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

int main()
{

	int t,r;
    scanf("%d%d",&t,&r);
    vector<pair<int,int>>p(t);
    for(int i=0;i<t;i++)
    {
    	int x;
    	scanf("%d",&x);
    	p[i].first=x;
    	p[i].second=i+1;

    }
    sort(p.rbegin(),p.rend());

    printf("%d\n",p[r-1].first);
    for(int i=0;i<r;i++)
    {
    	printf("%d ",p[i].second);
    }

}


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

int main()
{

	int t,r;
    scanf("%d%d",&t,&r);
    vector<int>p,re;
    for(int i=0;i<t;i++)
    {
    	int x;
    	scanf("%d",&x);
    	 p.push_back(x);
    }
    int tmp=r,val;

    for(int i=0;i<t;i++)
    {
    	int in=0,v=-1;
    	for(int j=0;j<t;j++)
    	{
    		if(p[j]>v)
    		{
    			v=p[j];
    			in=j;
    		}
    	}
    	val=p[in];
    	p[in]=-1;
    	re.push_back(in+1);
    tmp--;
    if(!tmp)
    	break;
    }
    cout<<val<<"\n";
    for(int i=re.size()-1;i>=0;i--)
    {
    	cout<<re[i]<<" ";
    }

}


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

int main()
{

	int t,r;
    scanf("%d%d",&t,&r);
    vector<pair<int,int>>p;
    for(int i=0;i<t;i++)
    {
    	int x;
    	pair<int,int>tm;
    	scanf("%d",&x);
    	tm.first=x;
    	tm.second=i+1;
         p.push_back(tm);
    }
    sort(p.begin(),p.end());

    printf("%d\n",p[t-r].first);
    for(int i=t-1;i>=0&&r;i--)
    {
    	printf("%d ",p[i].second);
    	r--;
    }

}


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

int main()
{

	int t,r;
    cin>>t>>r;
    vector<pair<int,int>>p;
    for(int i=0;i<t;i++)
    {
    	int x;
    	    	pair<int,int>tm;
    	    	cin>>x;
    	    	tm.first=x;
    	    	tm.second=i+1;
    	         p.push_back(tm);

    }
    sort(p.begin(),p.end());

    printf("%d\n",p[t-r].first);
    for(int i=t-1;i>=t-r;i--)
    {
    	printf("%d ",p[i].second);
    }

}


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

int main()
{
	pair<int,int>p[1001];
	int t,r;
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    cin>>t>>r;

    for(int i=0;i<t;i++)
    {
    	cin>>p[i].first;
    	p[i].second=i+1;

    }
    sort(p,p+t);

    printf("%d\n",p[t-r].first);
    for(int i=t-1;i>=t-r;i--)
    {
    	printf("%d ",p[i].second);
    }

}


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

pair<int,int>p[1001];
int main()
{

	int t,r;
    cin>>t>>r;

    for(int i=0;i<t;i++)
    {
    	cin>>p[i].first;
    	p[i].second=i+1;

    }
    sort(p,p+t);

    printf("%d\n",p[t-r].first);
    for(int i=t-1;i>=t-r;i--)
    {
    	printf("%d ",p[i].second);
    }

}


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

int main()
{

	int t,r;
    scanf("%d%d",&t,&r);
    vector<int>p,re;
    for(int i=0;i<t;i++)
    {
    	int x;
    	scanf("%d",&x);
    	 p.push_back(x);
    }
    int tmp=r,val;

    for(int i=0;i<t;i++)
    {
    	int in=0,v=-1;
    	for(int j=0;j<t;j++)
    	{
    		if(p[j]>v)
    		{
    			v=p[j];
    			in=j;
    		}
    	}
    	val=p[in];
    	p[in]=-1;
    	re.push_back(in+1);
    tmp--;
    if(!tmp)
    	break;
    }
    cout<<val<<"\n";
    for(int i=0;i<re.size();i++)
    {
    	cout<<re[i]<<" ";
    }

}


#include <bits/stdc++.h>
using namespace std;
typedef    vector< int > vi;
//typedef    vector< vi > vvi;
//           map<int, int> g1;
//         vector< pair <int,int> > vect;
//           make_pair(arr[i],arr1[i]
//           sort(vect.begin(), vect.end());
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;

#define ll long long
#define forn(x,n) for(ll x = 0; x < n; ++x)
#define forni(j,i,n) for ( ll j=i ; j<n ; j++ )
#define ff first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)

#define MOD 1000000007
#define PI 3.14159265

int main() {
	ll n,m=0,x,y,count=0;
	cin>>n;
	cin>>x;
	forn(i,n-1){
		cin>>y;
		if(x>y)	m+=x-y,x=y;
		else x=y;
		cout<<m<<endl;
	}
	cout<<m;
}


#include <bits/stdc++.h>
using namespace std;
typedef    vector< int > vi;
//typedef    vector< vi > vvi;
//           map<int, int> g1;
//         vector< pair <int,int> > vect;
//           make_pair(arr[i],arr1[i]
//           sort(vect.begin(), vect.end());
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;

#define ll long long
#define forn(x,n) for(ll x = 0; x < n; ++x)
#define forni(j,i,n) for ( ll j=i ; j<n ; j++ )
#define ff first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)

#define MOD 1000000007
#define PI 3.14159265

int main() {
	  vector< pair <int,int> > vect;
	ll n,b,x;
	cin>>n>>b;
	forn(i,n){
		cin>>x;
		vect.pb(make_pair(x,i));
	}
	sort(vect.begin(),vect.end());
	cout<<vect[n-b].ff<<endl;
	forni(i,n-b,n)
	cout<<vect[i].ss+1<<" ";
}


#include <bits/stdc++.h>
using namespace std;
typedef    vector< int > vi;
//typedef    vector< vi > vvi;
//           map<int, int> g1;
//         vector< pair <int,int> > vect;
//           make_pair(arr[i],arr1[i]
//           sort(vect.begin(), vect.end());
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;

#define ll long long
#define forn(x,n) for(ll x = 0; x < n; ++x)
#define forni(j,i,n) for ( ll j=i ; j<n ; j++ )
#define ff first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)

#define MOD 1000000007
#define PI 3.14159265

int main() {
freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	  vector< pair <int,int> > vect;
	ll n,b,x;
	cin>>n>>b;
	forn(i,n){
		cin>>x;
		vect.pb(make_pair(x,i));
	}
	sort(vect.begin(),vect.end());
	cout<<vect[n-b].ff<<endl;
	forni(i,n-b,n)
	cout<<vect[i].ss+1<<" ";
}

�


#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
    long long  a,b;
}A[500005];
long long tree[500005],ans;
int cmp(node A,node B){
    return A.a<B.a;
}
int find(int len,int n)//修改后的二分查找，若返回值为x，则a[x]>=n
{
    int left=0,right=len,mid;
    while(left<=right){
        mid=(left+right)/2;
       if(n>A[mid].a) left=mid+1;
       else  right=mid-1;
    }
    return left;
}
int lowbit(long long x){
    return x&-x;
}

void add(int i,long long v){     //i表示现在输入的数要加上的位置，v表示的是这个位置要增加多大的值
    for(;i<=500000;i+=lowbit(i)){
        tree[i]+=v;
    }
}
long long sum(int i){
    long long  ans=0;
    for(;i>0;i-=lowbit(i)){
        ans+=tree[i];
    }
    return ans;
}
int main(void){
    int i,j,n,m,k;
    while(scanf("%d %d",&n,&m)!=EOF){
        for(i=0;i<n;i++) tree[i]=0;
        for(i=0;i<n;i++)
            scanf("%I64d %I64d",&A[i].a,&A[i].b);
        sort(A,A+n,cmp);
         for(i=0;i<n;i++)
            add(i+1,A[i].b);
        ans=0;
        for(i=0;i<n;i++){
            k=find(i,A[i].a-m);
            ans=max(sum(i+1)-sum(k),ans);
        }
        printf("%I64d\n",ans);
    }
}


#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
    long long  a,b;
}A[500005];
long long tree[500005],ans;
int cmp(node A,node B){
    return A.a<B.a;
}
int find(int len,int n)//修改后的二分查找，若返回值为x，则a[x]>=n
{
    int left=0,right=len,mid;
    while(left<=right){
        mid=(left+right)/2;
       if(n>A[mid].a) left=mid+1;
       else  right=mid-1;
    }
    return left;
}
int lowbit(long long x){
    return x&-x;
}

void add(int i,long long v){     //i表示现在输入的数要加上的位置，v表示的是这个位置要增加多大的值
    for(;i<=500000;i+=lowbit(i)){
        tree[i]+=v;
    }
}
long long sum(int i){
    long long  ans=0;
    for(;i>0;i-=lowbit(i)){
        ans+=tree[i];
    }
    return ans;
}
int main(void){
    int i,j,n,m,k;
    while(scanf("%d %d",&n,&m)!=EOF){
        for(i=0;i<=500005;i++) tree[i]=0;
        for(i=0;i<n;i++)
            scanf("%I64d %I64d",&A[i].a,&A[i].b);
        sort(A,A+n,cmp);
         for(i=0;i<n;i++)
            add(i+1,A[i].b);
        ans=0;
        for(i=0;i<n;i++){
            k=find(i,A[i].a-m);
            ans=max(sum(i+1)-sum(k),ans);
        }
        printf("%I64d\n",ans);
    }
}


#include<iostream>
#include<algorithm>
using namespace std;
pair<int,int> num[100001];
int main()
{
	int n,w;
	while(cin >> n >> w)
	{
		for(int i=0;i<n;i++)
		{
			cin >> num[i].first >> num[i].second;
		}
		sort(num,num+n);
		int ans1 = num[0].second;
		int k;
		for(k=1;k<n;k++)
		{
			if(num[k].first-num[0].first >= w )break;
			ans1+=num[k].second;
		}

		int ans = ans1;

		for(int i=k,j = 0;i<n;i++,j++)
		{
			int flag = 0;
			while(num[i].first-num[j+1].first < w&&i<n)
			{
				flag = 1;
				ans1+=num[i].second;
				i++;
			}
			if(flag)i--;
			ans1-=num[j].second;
			ans = max(ans,ans1);

		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
pair<long long,long long> num[100001];
int main()
{
	int n,w;
	while(cin >> n >> w)
	{
		for(int i=0;i<n;i++)
		{
			cin >> num[i].first >> num[i].second;
		}
		sort(num,num+n);
		long long ans1 = num[0].second;
		int k;
		for(k=1;k<n;k++)
		{
			if(num[k].first-num[0].first >= w )break;
			ans1+=num[k].second;
		}

		long long ans = ans1;

		for(int i=k,j = 1;i<n&&j<n;j++)
		{
			int flag = 0;
			while(num[i].first-num[j].first < w&&i<n)
			{
				flag = 1;
				ans1+=num[i].second;
				i++;
			}
			if(flag)
			{

			ans1-=num[j-1].second;
			ans = max(ans,ans1);
			}
			else
			ans1-=num[j-1].second;

		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
pair<int,int> num[100001];
int main()
{
	int n,w;
	while(cin >> n >> w)
	{
		for(int i=0;i<n;i++)
		{
			cin >> num[i].first >> num[i].second;
		}
		sort(num,num+n);
		int ans1 = num[0].second;
		int k;
		for(k=1;k<n;k++)
		{
			if(num[k].first-num[0].first >= w )break;
			ans1+=num[k].second;
		}

		int ans = ans1;

		for(int i=k,j = 1;i<n&&j<n;j++)
		{
			int flag = 0;
			while(num[i].first-num[j].first < w&&i<n)
			{
				flag = 1;
				ans1+=num[i].second;
				i++;
			}
			if(flag)
			{

			ans1-=num[j-1].second;
			ans = max(ans,ans1);
			}
			else
			ans1-=num[j-1].second;

		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
pair<int,int> num[100001];
int main()
{
	int n,w;
	while(cin >> n >> w)
	{
		for(int i=0;i<n;i++)
		{
			cin >> num[i].first >> num[i].second;
		}
		sort(num,num+n);
		int ans1 = num[0].second;
		int k;
		for(k=1;k<n;k++)
		{
			if(num[k].first-num[0].first >= w )break;
			ans1+=num[k].second;
		}

		int ans = ans1;
		for(int i=k+1,j = 1;i<n;i++,j++)
		{
			while(num[i].first-num[j].first < w&&i<n)
			{

				ans1+=num[i].second;
				i++;
			}
			ans1-=num[j-1].second;
			ans = max(ans,ans1);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node
{
	int x,y;
};
Node node[100005];
int cmp(Node a,Node b)
{
	return a.x<b.x;
}
int main()
{
	int N,b;
	cin>>N>>b;
	long long s=0;
	long long MAX=0;
	for(int i=0;i<N;i++)
	{
		cin>>node[i].x>>node[i].y;
	}
	sort(node,node+N,cmp);
	int z=0;
	for(int i=0;i<N;i++)
	{
		while(node[i].x-node[z].x>=b)
		{
			s-=node[z].y;
			z++;
		}
		s+=node[i].y;
		if(MAX<s)
		{
			MAX=s;
		}
	}
    cout<<MAX<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node
{
	int x,y;
};
Node node[100005];
int cmp(Node a,Node b)
{
	return a.x<b.x;
}
int main()
{
	int N,b;
	cin>>N>>b;
	long long s=0;
	long long MAX=0;
	for(int i=0;i<N;i++)
	{
		cin>>node[i].x>>node[i].y;
		if(MAX<node[i].y)
		{
			MAX=node[i].y;
		}
	}
	sort(node,node+N,cmp);
	int z=0;
	for(int i=0;i<N;i++)
	{
		if(node[i].x-node[z].x>=b)
		{
			z++;
			s-=node[z].y;
		}
		s+=node[i].y;
		if(MAX<s)
		{
			MAX=s;
		}
	}
    cout<<MAX<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node
{
	int x,y;
};
Node node[100005];
int cmp(Node a,Node b)
{
	return a.x<b.x;
}
int main()
{
	int N,b;
	cin>>N>>b;
	long long s=0;
	long long MAX=0;
	for(int i=0;i<N;i++)
	{
		cin>>node[i].x>>node[i].y;
		if(MAX<node[i].y)
		{
			MAX=node[i].y;
		}
	}
	sort(node,node+N,cmp);
	if(N%2==0)
	{
		for(int i=0;i<N;i+=2)
		{
			if(node[i+1].x-node[i].x<b)
			{
				 s+=node[i].y+node[i+1].y;
			}
		}
	}
	else
	{
		for(int i=0;i<N-1;i+=2)
		{
			if(node[i+1].x-node[i].x<b)
			{
				 s+=node[i].y+node[i+1].y;
			}
		}
		if(node[N-1].x-node[N-2].x<b)
		{
			s+=node[N-1].y;
		}
	}
	if(MAX<s)
		MAX=s;
    cout<<MAX<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node
{
	int x,y;
};
Node node[100005];
int cmp(Node a,Node b)
{
	return a.x<b.x;
}
int main()
{
	int N,b;
	cin>>N>>b;
	long long s=0;
	int MAX=0;
	for(int i=0;i<N;i++)
	{
		cin>>node[i].x>>node[i].y;
		if(MAX<node[i].y)
		{
			MAX=node[i].y;
		}
	}
	sort(node,node+N,cmp);
	for(int i=0;i<N;i++)
	{
		if(node[i+1].x-node[i].x<b)
		{
             s+=node[i].y+node[i+1].y;
			 i++;
		}
	}
	if(MAX<s)
		MAX=s;
    cout<<MAX<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node
{
	int x,y;
};
Node node[100005];
int cmp(Node a,Node b)
{
	return a.x>b.x;
}
int main()
{
	int N,b;
	cin>>N>>b;
	long long s=0;
	int MAX=0;
	for(int i=0;i<N;i++)
	{
		cin>>node[i].x>>node[i].y;
		if(MAX<node[i].y)
		{
			MAX=node[i].y;
		}
	}
	sort(node,node,cmp);
	for(int i=0;i<N;i++)
	{
		if(node[i+1].x-node[i].x<b)
		{
             s+=node[i].y;
		}
	}
	if(MAX<s)
		MAX=s;
    cout<<MAX<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node
{
	int x,y;
};
Node node[100005];
int cmp(Node a,Node b)
{
	return a.x>b.x;
}
int main()
{
	int N,b;
	cin>>N>>b;
	long long s=0;
	int MAX=0;
	for(int i=0;i<N;i++)
	{
		cin>>node[i].x>>node[i].y;
		if(MAX<node[i].y)
		{
			MAX=node[i].y;
		}
	}
	sort(node,node,cmp);
	for(int i=0;i<N;i++)
	{
		if(node[i+1].x-node[i].x<=b)
		{
             s+=node[i].y;
		}
	}
	if(MAX<s)
		MAX=s;
    cout<<MAX<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
struct oo{
	__int64 a, b;
};
int main()
{
	long long n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	oo st[100001];
	for(i = 1; i <= n; i++)
		scanf("%I64d%I64d", &st[i].a, &st[i].b);

	for(i = 1; i <= n; i++)
	for(j = i; j <= n; j++)
	{
		if(st[i].a > st[j].a)
		{
			st[0] = st[i];
			st[i] = st[j];
			st[j] = st[0];
		}
	}
	for(i = 2; i <= n; i++)
	st[i].b = st[i-1].b + st[i].b;
	t = st[1].b;
	st[0].b = 0;
	j = 1;
	for(i = 1; i <= n; i++)
	{
		l = 0;
		for(; j <= n; j++)
		if(st[j].a - st[i].a < m)
		l = st[j].b - st[i-1].b;
		else
		break;
		if(t < l)
		t = l;
		if(j == n+1)
		break;
	}
	cout <<  t << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct oo{
	__int64 a, b;
};
bool cm(struct oo x,struct oo y)
{
	return x.a < y.a;
}
int main()
{
	long long n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	oo st[100001];
	for(i = 1; i <= n; i++)
		scanf("%I64d%I64d", &st[i].a, &st[i].b);
	sort(st+1, st+n+1, cm);
	for(i = 2; i <= n; i++)
	st[i].b = st[i-1].b + st[i].b;
	t = st[1].b;
	st[0].b = 0;
	j = 1;
	for(i = 1; i <= n; i++)
	{
		l = 0;
		for(; j <= n; j++)
		if(st[j].a - st[i].a < m)
		l = st[j].b - st[i-1].b;
		else
		break;
		if(t < l)
		t = l;
		if(j == n+1)
		break;
	}
	cout <<  t << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
struct oo{
	__int64 a, b;
};
bool cm(struct oo x,struct oo y)
{
	return x.a > y.a;
}
int main()
{
	long long n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	oo st[100001];
	for(i = 1; i <= n; i++)
		scanf("%I64d%I64d", &st[i].a, &st[i].b);

	for(i = 1; i <= n; i++)
	for(j = i; j <= n; j++)
	{
		if(st[i].a > st[j].a)
		{
			st[0] = st[i];
			st[i] = st[j];
			st[j] = st[0];
		}
	}
	for(i = 2; i <= n; i++)
	st[i].b = st[i-1].b + st[i].b;
	t = st[1].b;
	st[0].b = 0;
	j = 1;
	for(i = 1; i <= n; i++)
	{
		l = 0;
		for(; j <= n; j++)
		if(st[j].a - st[i].a < m)
		l = st[j].b - st[i-1].b;
		else
		break;
		if(t < l)
		t = l;
		if(j == n+1)
		break;
	}
	cout <<  t << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
struct oo{
	long long a, b;
};
int main()
{
	long long n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	oo st[100001];
	for(i = 1; i <= n; i++)
		cin >> st[i].a >> st[i].b;

	for(i = 1; i <= n; i++)
	for(j = i; j <= n; j++)
	{
		if(st[i].a > st[j].a)
		{
			st[0] = st[i];
			st[i] = st[j];
			st[j] = st[0];
		}
	}
	for(i = 2; i <= n; i++)
	st[i].b = st[i-1].b + st[i].b;
	t = st[1].b;
	st[0].b = 0;
	j = 1;
	for(i = 1; i <= n; i++)
	{
		l = 0;
		for(; j <= n; j++)
		if(st[j].a - st[i].a < m)
		l = st[j].b - st[i-1].b;
		else
		break;
		if(t < l)
		t = l;
	}
	cout <<  t << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
struct oo{
	__int64 a, b;
};
int main()
{
	long long n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	oo st[100001];
	for(i = 1; i <= n; i++)
		scanf("%I64d%I64d", &st[i].a, &st[i].b);

	for(i = 1; i <= n; i++)
	for(j = i; j <= n; j++)
	{
		if(st[i].a > st[j].a)
		{
			st[0] = st[i];
			st[i] = st[j];
			st[j] = st[0];
		}
	}
	for(i = 2; i <= n; i++)
	st[i].b = st[i-1].b + st[i].b;
	t = st[1].b;
	st[0].b = 0;
	j = 1;
	for(i = 1; i <= n; i++)
	{
		l = 0;
		for(; j <= n; j++)
		if(st[j].a - st[i].a < m)
		l = st[j].b - st[i-1].b;
		else
		break;
		if(t < l)
		t = l;
	}
	cout <<  t << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
struct oo{
	int a, b;
};
int main()
{
	int n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	oo st[10001];
	for(i = 1; i <= n; i++)
		cin >> st[i].a >> st[i].b;

	for(i = 1; i <= n; i++)
	for(j = i; j <= n; j++)
	{
		if(st[i].a > st[j].a)
		{
			st[0] = st[i];
			st[i] = st[j];
			st[j] = st[0];
		}
	}
	for(i = 2; i <= n; i++)
	st[i].b = st[i-1].b + st[i].b;
	t = st[1].b;
	st[0].b = 0;
	for(i = 1; i <= n; i++)
	{
		l = 0;
		for(j = i; j <= n; j++)
		if(st[j].a - st[i].a < m)
		l = st[j].b - st[i-1].b;
		else
		break;
		if(t < l)
		t = l;
	}
	cout <<  t << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
struct oo{
	long long a, b;
};
int main()
{
	long long n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	oo st[10001];
	for(i = 1; i <= n; i++)
		cin >> st[i].a >> st[i].b;

	for(i = 1; i <= n; i++)
	for(j = i; j <= n; j++)
	{
		if(st[i].a > st[j].a)
		{
			st[0] = st[i];
			st[i] = st[j];
			st[j] = st[0];
		}
	}
	for(i = 2; i <= n; i++)
	st[i].b = st[i-1].b + st[i].b;
	t = st[1].b;
	st[0].b = 0;
	for(i = 1; i <= n; i++)
	{
		l = 0;
		for(j = i; j <= n; j++)
		if(st[j].a - st[i].a < m)
		l = st[j].b - st[i-1].b;
		else
		break;
		if(t < l)
		t = l;
	}
	cout <<  t << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
struct oo{
	int a, b;
};
int main()
{
	int n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	for(i = 1; i <= n; i++)
	{
		cin >> k >> l;
		if(m > k)
		t += l;
	}
	cout <<  t << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
struct oo{
	long long a, b;
};
int main()
{
	long long n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	oo st[100001];
	for(i = 1; i <= n; i++)
		cin >> st[i].a >> st[i].b;

	for(i = 1; i <= n; i++)
	for(j = i; j <= n; j++)
	{
		if(st[i].a > st[j].a)
		{
			st[0] = st[i];
			st[i] = st[j];
			st[j] = st[0];
		}
	}
	for(i = 2; i <= n; i++)
	st[i].b = st[i-1].b + st[i].b;
	t = st[1].b;
	st[0].b = 0;
	for(i = 1; i <= n; i++)
	{
		l = 0;
		for(j = i; j <= n; j++)
		if(st[j].a - st[i].a < m)
		l = st[j].b - st[i-1].b;
		else
		break;
		if(t < l)
		t = l;
	}
	cout <<  t << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
struct oo{
	int a, b;
};
int main()
{
	int n, m, i, j, k, l, t = 0;
	cin >> n >> m;
	oo st[10001];
	for(i = 1; i <= n; i++)
		cin >> st[i].a >> st[i].b;

	for(i = 1; i <= n; i++)
	for(j = i; j <= n; j++)
	{
		if(st[i].a > st[j].a)
		{
			st[0] = st[i];
			st[i] = st[j];
			st[j] = st[0];
		}
	}
	for(i = 2; i <= n; i++)
	st[i].b = st[i-1].b + st[i].b;
	t = st[1].b;
	st[0].b = 0;
	for(i = 1; i <= n; i++)
	{
		l = 0;
		for(j = i; j <= n; j++)
		if(st[j].a - st[i].a < m)
		l = st[j].b - st[j-1].b;
		else
		break;
		if(t < l)
		t = l;
	}
	cout <<  t << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

typedef pair<long, long> pii;

long n, d;
vector<pii> a;

int main()
{
    cin >> n >> d;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        long m, s;
        cin >> m >> s;
        a[i] = make_pair(m, s);
    }
    sort(a.begin(), a.end());

    long mx = 0;
    long j = 0;
    long cd = a[0].first;
    long cur = 0;
    while ((j < n) && (a[j].first <= (cd + d))) {
        cur += a[j].second;
        j++;
    }
    mx = cur;

    for (int i = 1; i < n; i++) {
        cur -= a[i - 1].second;
        cd = a[i].first;
        while ((j < n) && (a[j].first <= (cd + d))) {
            cur += a[j].second;
            j++;
        }
        mx = max(mx, cur);
    }

    cout << mx;
    cin >> n;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

typedef pair<int, int> pii;

int n, d;
vector<pii> a;

int main()
{
    cin >> n >> d;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        int m, s;
        cin >> m >> s;
        a[i] = make_pair(m, s);
    }
    sort(a.begin(), a.end());

    int mx = 0;
    int j = 0;
    int cd = a[0].first;
    int cur = 0;
    while ((j < n) && (a[j].first <= (cd + d))) {
        cur += a[j].second;
        j++;
    }
    mx = cur;

    for (int i = 1; i < n; i++) {
        cur -= a[i - 1].second;
        cd = a[i].first;
        while ((j < n) && (a[j].first <= (cd + d))) {
            cur += a[j].second;
            j++;
        }
        mx = max(mx, cur);
    }

    cout << mx;
    cin >> n;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

typedef pair<long, long> pii;

long n, d;
vector<pii> a;

int main()
{
    cin >> n >> d;
    a.resize(n+1,make_pair(0,0));
    for (long i = 1; i <= n; i++) {
        long m, s;
        cin >> m >> s;
        a[i] = make_pair(m, s);
    }
    sort(a.begin(), a.end());

    long mx = 0;
    long j = 1;
    long cd = 0;
    long cur = 0;

    for (long i = 1; i <= n; i++) {
        cur -= a[i - 1].second;
        cd = a[i].first;
        while ((j <= n) && (a[j].first < (cd + d))) {
            cur += a[j].second;
            j++;
        }
        mx = max(mx, cur);
    }

    cout << mx;
    cin >> n;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

typedef pair<long, long> pii;

long n, d;
vector<pii> a;

int main()
{
    cin >> n >> d;
    a.resize(n);
    for (long i = 0; i < n; i++) {
        long m, s;
        cin >> m >> s;
        a[i] = make_pair(m, s);
    }
    sort(a.begin(), a.end());

    long mx = 0;
    long j = 0;
    long cd = a[0].first;
    long cur = 0;
    while ((j < n) && (a[j].first < (cd + d))) {
        cur += a[j].second;
        j++;
    }
    mx = cur;

    for (long i = 1; i < n; i++) {
        cur -= a[i - 1].second;
        cd = a[i].first;
        while ((j < n) && (a[j].first < (cd + d))) {
            cur += a[j].second;
            j++;
        }
        mx = max(mx, cur);
    }

    cout << mx;
    cin >> n;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

typedef pair<long long, long long> pii;

long n, d;
vector<pii> a;

int main()
{
    cin >> n >> d;
    a.resize(n+1,make_pair(0,0));
    for (long long i = 1; i <= n; i++) {
        long long m, s;
        cin >> m >> s;
        a[i] = make_pair(m, s);
    }
    sort(a.begin(), a.end());

    long long mx = 0;
    long long j = 1;
    long long cd = 0;
    long long cur = 0;

    for (long long i = 1; i <= n; i++) {
        cur -= a[i - 1].second;
        cd = a[i].first;
        while ((j <= n) && (a[j].first < (cd + d))) {
            cur += a[j].second;
            j++;
        }
        mx = max(mx, cur);
    }

    cout << mx;
    cin >> n;
    return 0;
}


#include <iostream>
#include <conio.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long
#define MP make_pair

const int MAX_VALUE = 1e9 + 7;

pair<int, int> a[111111];
ll sum[111111];

int main() {
    int n = 0;
    int d = 0;
    cin >> n >> d;

    for (int i = 0; i < n; ++i) {
        int m = 0;
        int s = 0;
        cin >> m >> s;
        a[i] = MP(m, s);
    }
    a[n] = MP(0, 0);
    sort(a, a + n + 1);

    for (int i = 1; i < n + 1; ++i) {
        sum[i] = sum[i - 1] + a[i].second;
    }

    int j = 0;
    int k = 0;
    ll ans = 0;
    for (int i = 1; i < n + 1; ++i) {
        while (j <= i && a[j].first + d <= a[i].first) j++;

        ans = max(ans, sum[i] - sum[j - 1]);
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <conio.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long
#define MP make_pair

const int MAX_VALUE = 1e9 + 7;

pair<int, int> a[111111];
ll sum[111111];

int main() {
    int n = 0;
    int d = 0;
    cin >> n >> d;

    for (int i = 0; i < n; ++i) {
        int m = 0;
        int s = 0;
        cin >> m >> s;
        a[i] = MP(m, s);
    }

    sort(a, a + n + 1);

    for (int i = 1; i < n + 1; ++i) {
        sum[i] = sum[i - 1] + a[i].second;
    }

    int j = 0;
    int k = 0;
    ll ans = 0;
    for (int i = 1; i < n + 1; ++i) {
        while (j <= i && a[j].first + d <= a[i].first) j++;

        ans = max(ans, sum[i] - sum[j - 1]);
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <conio.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long
#define MP make_pair

const int MAX_VALUE = 1e9 + 7;

pair<int, int> a[111111];
ll sum[111111];

int main() {
    int n = 0;
    int d = 0;
    cin >> n >> d;

    for (int i = 0; i < n; ++i) {
        int m = 0;
        int s = 0;
        cin >> m >> s;
        a[i] = MP(m, s);
    }
    a[n] = MP(0, 0);
    sort(a, a + n + 1);

    sum[0] = 0;
    for (int i = 1; i < n + 1; ++i) {
        sum[i] = sum[i - 1] + a[i].second;
    }

    int j = 1;
    int k = 1;
    ll ans = 0;
    for (int i = 1; i < n + 1; ++i) {
        while (j <= i && a[j].first + d <= a[i].first) j++;

        ans = max(ans, sum[i] - sum[j - 1]);
       // cout << j << " " << i << " " << ans << endl;
    }

    /*for (int i = 0; i < n + 1; ++i) {
        cout << a[i].first << " " << a[i].second << endl;
    }

    for (int i = 0; i < n + 1; ++i) {
        cout << sum[i] <<  " ";
    }
    cout << endl;*/

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <conio.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long
#define MP make_pair

const int MAX_VALUE = 1e9 + 7;

pair<int, int> a[111111];
ll sum[111111];

int main() {
    int n = 0;
    int d = 0;
    cin >> n >> d;

    for (int i = 0; i < n; ++i) {
        int m = 0;
        int s = 0;
        cin >> m >> s;
        a[i] = MP(m, s);
    }
    a[n] = MP(0, 0);
    sort(a, a + n + 1);

    sum[0] = 0;
    for (int i = 1; i < n + 1; ++i) {
        sum[i] = sum[i - 1] + a[i].second;
    }

    int j = 0;
    int k = 0;
    ll ans = 0;
    for (int i = 1; i < n + 1; ++i) {
        while (j <= i && a[j].first + d <= a[i].first) j++;

        ans = max(ans, sum[i] - sum[j - 1]);
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <fstream>

typedef long long ll;

using namespace std;

int com(const void * x, const void * y){
	return (*(int*)x - *(int*)y);
}

int main(){
	//ifstream fin("input.txt");
	ll n, d;
	cin >> n >> d;
	vector<ll> m(n), s1(n);
	for (int i = 0; i < n; i++){
		cin >> m[i] >> s1[i];
	}
	ll max = 0;
	for (ll i = 0; i < n; i++){
		if (max < m[i])
			max = m[i];
	}
	vector<ll> s(max+1);
	for (int i = 0; i < n; i++){
		if (s[m[i]] < s1[i]){
			s[m[i]] = s1[i];
		}
	}
	qsort(&m[0], n, sizeof(ll), com);
	//for (ll i = 0; i < n; i++) cout << m[i] << " ";
	vector<ll> sum(n);
	ll count = 0; //the length of sum at the moment
	sum[0] = s[m[0]];
	for (ll i = 0; i < n - 1; i++){
		if ((m[i + 1] - m[i] < d) && -((m[i + 1] - m[i]) < d)){
			sum[count] += s[m[i+1]];
		}
		else{
			count++;
			sum[count] = s[m[i + 1]];
		}
	}
	max = 0;
	for (ll i = 0; i < n; i++){
		if (max < sum[i]){
			max = sum[i];
		}
	}
	cout << max << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <fstream>

typedef long long ll;

using namespace std;

int com(const void * x, const void * y){
	return (*(ll*)x - *(ll*)y);
}

int main(){
	//ifstream fin("input.txt");
	ll n, d;
	cin >> n >> d;
	vector<ll> m(n), s1(n);
	for (ll i = 0; i < n; i++){
		cin >> m[i] >> s1[i];
	}
	ll max = 0;
	for (ll i = 0; i < n; i++){
		if (max < m[i])
			max = m[i];
	}
	vector<ll> s(max+1);
	for (ll i = 0; i < n; i++){
		if (s[m[i]] < s1[i]){
			s[m[i]] = s1[i];
		}
	}
	qsort(&m[0], n, sizeof(ll), com);
	//for (ll i = 0; i < n; i++) cout << m[i] << " ";
	vector<ll> sum(n);
	ll count = 0; //the length of sum at the moment
	int num = 0; //number of the first guest in the new party
	sum[0] = s[m[0]];
	for (ll i = 0; i < n - 1; i++){
		if ((m[i + 1] - m[num] < d) && -((m[i + 1] - m[num]) < d)){
			sum[count] += s[m[i+1]];
		}
		else{
			num = i + 1;
			count++;
			sum[count] = s[m[i + 1]];
		}
	}
	max = 0;
	for (ll i = 0; i < n; i++){
		if (max < sum[i]){
			max = sum[i];
		}
	}
	cout << max << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <fstream>

#define F first
#define S second

using namespace std;

int main(){
	//ifstream fin("input.txt");
	const int N = 100001;
	pair<int, int> a[N];
	int n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++){
		cin >> a[i].F >> a[i].S;
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++){
		cout << a[i].first << " " << a[i].second << endl;
	}
	int sum = 0;// the sum of elements from i to j;
	int j = 0;//the second pointer;
	int ans = 0;
	for (int i = 0; i < n; i++){
		while (j < n && abs(a[i].F - a[j].F) < d){
			sum = sum + a[j].second;
			j++;
		}
		ans > sum ? ans = ans : ans = sum;
		if (j >= n) break;
		sum = sum - a[i].S;
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <fstream>

#define F first
#define S second

using namespace std;

int main(){
	//ifstream fin("input.txt");
	const int N = 100001;
	pair<int, int> a[N];
	int n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++){
		cin >> a[i].F >> a[i].S;
	}
	sort(a, a + n);
	int sum = 0;// the sum of elements from i to j;
	int j = 0;//the second pointer;
	int ans = 0;
	for (int i = 0; i < n; i++){
		while (j < n && abs(a[i].F - a[j].F) < d){
			sum = sum + a[j].second;
			j++;
		}
		ans > sum ? ans = ans : ans = sum;
		if (j >= n) break;
		sum = sum - a[i].S;
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

#define F first
#define S second
typedef long long ll;

using namespace std;

int main(){
	int n;
	ll d;
	cin >> n >> d;
	const int N = 100001;
	pair<int, int> a[N];
	for (int i = 0; i < n; i++){
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a + n);
	int sum = 0;
	int ans = 0;
	int j = 0; //second pointer;
	for (int i = 0; i < n; i++){
		while (j < n && abs(a[i].first - a[j].first) < d){
			sum += a[j].second;
			j++;
		}
		ans < sum ? ans = sum : ans = ans;
		if (j = n){
			break;
		}
		sum = sum - a[i].S;
	}
	cout << ans << endl;
	return 0;
}