You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
583 B
27 lines
583 B
2 years ago
|
#include <bits/stdc++.h>
|
||
|
using namespace std;
|
||
|
|
||
|
const int N = 1010, INF = 1e8;
|
||
|
|
||
|
int n, m;
|
||
|
int id[N];
|
||
|
|
||
|
int main() {
|
||
|
cin >> n >> m;
|
||
|
for (int i = 0; i < n; i++) cin >> id[i];
|
||
|
|
||
|
while (m--) {
|
||
|
int l;
|
||
|
string num;
|
||
|
cin >> l >> num;
|
||
|
int res = INF;
|
||
|
for (int i = 0; i < n; i++) {
|
||
|
string s = to_string(id[i]);
|
||
|
if (s.size() >= l && s.substr(s.size() - l) == num)
|
||
|
res = min(res, id[i]);
|
||
|
}
|
||
|
if (res == INF) res = -1;
|
||
|
cout << res << endl;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|