i just solved a codeforces problem and i found something new about the find() c++ stl in the author's tutorial solution...but i cant understand that. here, in find(a.begin(), a.end(), s-i) == a.end()
what does the==a.end()
do?
(link to the question: http://codeforces.com/contest/1293/problem/A)
//Author's tutorial solution
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int n, s, k;
vector<int> a;
void Input() {
cin >> n >> s >> k; a.clear(); a.resize(k);
for (auto &z: a) cin >> z;
}
void Solve() {
for (int i=0; i<=k; i++) {
if (s-i >= 1 && find(a.begin(), a.end(), s-i) == a.end()) {cout << i << endl; return;} //SEE HERE
if (s+i <= n && find(a.begin(), a.end(), s+i) == a.end()) {cout << i << endl; return;} //SEE HERE
}
assert(false);
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int T; cin >> T; while (T--) {Input(); Solve();} return 0;
}