Sai_t @ 2020-10-15 21:29:51
#include<bits/stdc++.h>
using namespace std;
int n,q,a[1001],b[1001],c[1001],tens[9]={0,1};
bool cd(int bk,int len,int nd){
int ms=bk-nd;
if(ms<0)return false;
if(ms%tens[len])return false;
return true;
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
for(int i=2;i<9;i++)tens[i]=tens[i-1]*10;
cin>>n>>q;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<q;i++){
cin>>b[i]>>c[i];
}
for(int i=0;i<q;i++){
int ans=-1;
for(int j=0;j<n;j++){
// cout<<ans<<' ';
if(!cd(a[j],b[i],c[i]))continue;
if(ans<0)ans=a[j];
else ans=min(ans,a[j]);
}
cout<<ans<<endl;
}
return 0;
}