-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrute2sum.cpp
More file actions
38 lines (36 loc) · 838 Bytes
/
brute2sum.cpp
File metadata and controls
38 lines (36 loc) · 838 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
38
#include <bits/stdc++.h>
using namespace std;
string exists(vector<int>&a, int target){
int n = a.size();
for(int i = 0; i<n; i++){
for(int j = i+1; j<n; j++){
if(a[i]+a[j]==target){
return "YES";
}
}
}
return "NO";
}
vector<int>indices(vector<int>&a, int target){
int n = a.size();
for(int i = 0; i<n; i++){
for(int j = i+1; j<n; j++){
if(a[i]+a[j]==target){
return {i, j};
}
}
}
return {-1, -1};
}
int main(){
int n, target;
cin >> n >> target;
vector<int>a(n);
for(int i = 0; i<n; i++){
cin >> a[i];
}
cout << exists(a, target) << endl;
vector<int> res = indices(a, target);
cout << "[ " << res[0] << ", " << res[1] << " ]" << endl;
return 0;
}