Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- int main() {
- ifstream fin("input.txt");
- int count, number;
- fin >> count; // количество чисел
- vector<int> vec(count);
- for (size_t i = 0; i < count; i++) {
- fin >> vec[i];
- }
- fin >> number; // загаданное число
- int current_sum;
- size_t left = 0, right = count - 1;
- while (left < right) {
- current_sum = vec[left] + vec[right];
- if (current_sum == number) {
- cout << vec[left] << " " << vec[right] << endl;
- return 0;
- }
- current_sum < number ? left++ : right--;
- }
- cout << "None" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment