-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday33.cpp
More file actions
37 lines (34 loc) · 930 Bytes
/
day33.cpp
File metadata and controls
37 lines (34 loc) · 930 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
vector<int> findLanterns(const vector<int>& brightness, int target) {
int left = 0;
int right = brightness.size() - 1;
while (left < right) {
int sum = brightness[left] + brightness[right];
if (sum == target) {
return {left + 1, right + 1}; // 1-based indices
} else if (sum < target) {
left++;
} else {
right--;
}
}
return {}; // This will never be reached since there is exactly one solution
}
int main() {
int T;
cin >> T;
while (T--) {
int n, target;
cin >> n;
vector<int> brightness(n);
for (int i = 0; i < n; i++) {
cin >> brightness[i];
}
cin >> target;
vector<int> result = findLanterns(brightness, target);
cout << result[0] << " " << result[1] << endl;
}
return 0;
}