-
Notifications
You must be signed in to change notification settings - Fork 0
/
SumOfTwoValues.cpp
52 lines (51 loc) · 1.05 KB
/
SumOfTwoValues.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
vector<pair<int,int>>v;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
v.push_back(make_pair(a,i+1));
}
sort(v.begin(),v.end());
int m=0;int low=0;int high=n-1;int mid=0;
while(low<=high)
{
mid=low+(high-low)/2;
if(v[mid].first>=k)
high=mid-1;
else
{
m=mid;
low=mid+1;
}
}
int f=0;
for(int i=0;i<=m;i++)
{
int x=v[i].first;
low=i+1;high=n-1;mid=0;
while(low<=high)
{
mid=low+(high-low)/2;
if(v[mid].first+x==k)
{
cout<<v[i].second<<" "<<v[mid].second<<endl;
f=1;
break;
}
else if(x+v[mid].first<k)
low=mid+1;
else
high=mid-1;
}
if(f==1)
break;
}
if(f==0)
cout<<"IMPOSSIBLE"<<endl;
}