Skip to content

Instantly share code, notes, and snippets.

@vvolhejn
Created August 14, 2019 20:29
Show Gist options
  • Select an option

  • Save vvolhejn/297fa82def8446bfed5c5a5e49520ba3 to your computer and use it in GitHub Desktop.

Select an option

Save vvolhejn/297fa82def8446bfed5c5a5e49520ba3 to your computer and use it in GitHub Desktop.
MO-P ukazkova uloha reseni 2
#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