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
| #include <bits/stdc++.h>
using namespace std; const int maxn = 1e7 + 7; int n, m; vector<int> a(maxn), b(maxn); vector<int> mka(maxn, -1), mkb(maxn, -1); vector<int> pa, pb; vector<array<int, 2>> su(2 * maxn, {-1, -1}); pair<pair<int, int>, pair<int, int>> ans = {{-1, -1}, {-1, -1}}; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (mka[a[i]] == -1) { mka[a[i]] = i; pa.push_back(i); } else { ans.first.first = mka[a[i]]; ans.first.second = i; } } for (int i = 1; i <= m; i++) { scanf("%d", &b[i]); if (mkb[b[i]] == -1) { mkb[b[i]] = i; pb.push_back(i); } else { ans.second.first = mkb[b[i]]; ans.second.second = i; } } if (ans.first.first != -1 && ans.second.first != -1) { printf("%d %d %d %d", ans.first.first, ans.first.second, ans.second.first, ans.second.second); return 0; } for (int i : pa) { for (int j : pb) { if (su[a[i] + b[j]][0] == -1) { su[a[i] + b[j]] = {i, j}; } else { printf("%d %d %d %d", su[a[i] + b[j]][0], i, j, su[a[i] + b[j]][1]); return 0; } } } cout << "-1\n"; return 0; }
|