Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define FOR(i,a,b) for(i=a;i<=b;i++)
- using namespace std;
- pair<long long,long long> a[1000000];
- vector<long long > b;
- vector<long long > RES;
- map<long long,long long> cnt;
- map<long long,long long> M;
- map<long long,long long>::iterator it;
- long long i,n,res,S,x,y,h,k,res1,res2,res3,res4,min1,min2;
- long long binsearch_left(vector<long long> A ,long long L,long long R ,long long val)
- {
- while (L < R)
- {
- long long m = floor((L+R)/2);
- if (A[m]<val) L=m+1;
- else R=m;
- }
- return L;
- }
- int main(){
- cin>>n>>S;
- FOR(i,1,n) {cin>>a[i].first; a[i].second=i;}
- sort(a+1,a+1+n);
- FOR(i,1,n) {
- if (cnt.find(a[i].first)==cnt.end())cnt[a[i].first]=1; else cnt[a[i].first]++;
- if (M.find(a[i].first)==M.end()) M[a[i].first]=a[i].second;
- else if (a[i].second< M[a[i].first]) M[a[i].first]=a[i].second;
- }
- for(it=cnt.begin();it!=cnt.end();it++)
- if ((it->second)>1)
- b.push_back(it->first);
- sort(b.begin(),b.end());
- //if (b[i].first>=4) res=MAX(res,b[i].first*b[i].first);
- // FOR(i,0,b.size()-1)
- // cout<<b[i]<<" ";
- // cout<<endl<<endl;
- //FOR(i,0,b.size()-1)
- //cout<<b[i]<<" "<<binsearch_left(b,0,b.size()-1,S/b[i])<<" "<<endl;
- //cout<<endl;
- res=0;
- if (b.size()==0) {cout<<"-1"; return 0;}
- FOR(i,0,b.size()-1)
- {
- x=S/b[i];
- y=binsearch_left(b,0,b.size()-1,x);
- if (y!=i)
- {
- if ((b[i]*b[y]>res) && (b[i]*b[y]<=S))
- { res=b[i]*b[y];
- h=b[i];
- k=b[y];
- }
- else
- if(((b[i]*b[y])==res) && (b[i]*b[y]<=S))
- {
- min1=min(M[h],M[k]);
- min2=min(M[b[i]],M[b[y]]);
- if (min1>min2) {h=b[i]; k=b[y];}
- }
- }
- else if ((cnt[b[i]]>3)&&(b[i]*b[y]<=S))
- if (b[i]*b[y]>res)
- {res=b[i]*b[y];
- h=b[i];
- k=b[y];}
- else if ((b[i]*b[y])==res)
- {
- min1=min(M[h],M[k]);
- min2=min(M[b[i]],M[b[y]]);
- if (min1>min2) {h=b[i]; k=b[y];}
- }
- }
- if (res==0) {cout<<"-1"; return 0;}
- //cout<<res<<" "<<h<<" "<<k<<endl;
- FOR(i,1,n) if (a[i].first==h){res1=i; RES.push_back(a[i].second); break;}
- FOR(i,res1+1,n) if (a[i].first==h){res2=i; RES.push_back(a[i].second); break;}
- FOR(i,1,n) if (a[i].first==k) {res3=i; RES.push_back(a[i].second); break;}
- FOR(i,res3+1,n) if (a[i].first==k) {res4=i; RES.push_back(a[i].second); break;}
- sort(RES.begin(),RES.end());
- FOR(i,0,RES.size()-1) cout<<RES[i]<<" ";
- return 0;
- }
- /*
- 14 19
- 3 4 2 6 5 9 3 9 5 4 6 2 10 10
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement