Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main () {
- int n, target;
- cin >> n >> target;
- vector <int> arr(n);
- for (int i = 0; i < n; i++) cin >> arr[i];
- map <int, vector <int>> pos;
- for (int i = 0; i < n; i++) {
- pos[arr[i]].push_back(i);
- }
- for (int x = 0; x < n; x++) {
- int k = target - arr[x];
- //a_y = k and y != x
- if (pos.count(k) == 1) {
- bool valid = false;
- int cnt = 0;
- for (int pos_y: pos[k]) {
- if (pos_y != x) {
- valid = true;
- }
- cnt++;
- if (cnt == 2) break;
- }
- if (valid) {
- // tienes tu respuesta
- }
- }
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement