Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define vi vector<int>
- #define ll long long
- #define pb push_back
- #define mp make_pair
- #define ii pair<int, int>
- int main() {
- int n, m;
- cin >> n >> m;
- vi livro(n);
- for (int i = 0; i < n; i++) {
- cin >> livro[i];
- }
- sort(livro.begin(), livro.end());
- int x = -1, y = -1;
- for (int i = 0; i < n - 1 && livro[i] <= m / 2; i++) {
- for (int j = i + 1; j < n; j++) {
- if (livro[i] + livro[j] == m) {
- if (x == -1 || abs(x - y) > abs(livro[i] - livro[j])) {
- x = livro[i];
- y = livro[j];
- break;
- }
- }
- }
- }
- cout << x << " " << y << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment