Created
August 14, 2019 20:29
-
-
Save vvolhejn/297fa82def8446bfed5c5a5e49520ba3 to your computer and use it in GitHub Desktop.
MO-P ukazkova uloha reseni 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| int main() { | |
| int n, k; | |
| cin >> n >> k; | |
| vector<int> a(n); | |
| for (int i = 0; i < n; i++) { | |
| cin >> a[i]; | |
| } | |
| int vysledek_i = -1, vysledek_j = -1; | |
| int j = n - 1; | |
| for (int i = 0; i < n; i++) { | |
| while (j >= 0 && a[i] + a[j] > k) { | |
| j--; | |
| } | |
| if (a[i] + a[j] == k) { | |
| vysledek_i = i; | |
| vysledek_j = j; | |
| break; | |
| } | |
| } | |
| if (vysledek_i == -1) { | |
| // Nikdy jsme nenastavili vysledek_i, takze jsme nenasli reseni | |
| cout << "reseni neexistuje" << endl; | |
| } else { | |
| cout << (vysledek_i+1) << " " << (vysledek_j+1) << endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment