-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsumOfTwoValues.cpp
More file actions
93 lines (75 loc) · 1.32 KB
/
Copy pathsumOfTwoValues.cpp
File metadata and controls
93 lines (75 loc) · 1.32 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,i=0,x,c,d=0,e,y,z,l,k,j,h,g,idx,indx,xx=0,yy=0;
cin>>n;
int a[n],b[n];
cin>>x;
for(i=0;i<n;i++)
{
cin>>a[i];
b[i]=a[i];
}
sort(b,b+n);
if(x<b[n/2])
{
for(int i=0,e=n/2;i!=e;)
{
if(b[i]+b[e]>x)
{
e--;
}
else if(b[i]+b[e]<x)
{
i++;
}
else
{
y=b[i];
z=b[e];
d=1;
break;
}
}
}
else{
for(int i=0,e=n-1;i<e;)
{
if(b[i]+b[e]>x)
{
e--;
}
else if(b[i]+b[e]<x)
{
i++;
}
else
{
y=b[i];
z=b[e];
d=1;
break;
}
}
}
// cout<<"y="<<y<<" z="<<z<<endl;
if(d==0) cout<<"IMPOSSIBLE";
else
{
for(int i=0;i<n;i++)
{
if(a[i]==z)
{
cout<<i+1<<" ";
xx=1;
}
else if(a[i]==y)
{
cout<<i+1<<" ";
yy=1;
}
if(xx==1 && yy==1) break;
}
}
}