-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicecreamparlour.cpp
executable file
·55 lines (43 loc) · 1014 Bytes
/
icecreamparlour.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
53
54
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int T;
cin>>T;
while(T--){
int M,N;
int *in;
int *pos;
cin>>M;
cin>>N;
in = new int[N];
pos = new int[N];
for(int i = 0 ; i < N; ++i){
cin>>in[i];
pos[i] = in[i];
}
sort(in, in+N);
int s = 0;
int e = N - 1;
while(s != e){
if(in[s] + in[e] == M)
break;
if(in[s] + in[e] > M)
e--;
else
s++;
}
int i = 0;
while(i < N && pos[i] != in[s])
i++;
int first = i + 1;
i = N - 1;
while(i >=0 && pos[i] != in[e])
i--;
if(first < i + 1)
cout<<first << " " <<i+1<<endl;
else
cout<<i+1<< " " <<first<<endl;
}
return 0;
}