Created
January 26, 2019 05:39
-
-
Save 1604078-MEHEDI/c65a401a6a31d1aabb92aeb25de9ff74 to your computer and use it in GitHub Desktop.
This file contains 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 <bits/stdc++.h> | |
using namespace std; | |
#define INF 1<<30 | |
#define MAX 10005 | |
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); | |
typedef long long ll; | |
int main() | |
{ | |
FASTIO | |
///* | |
//double start_time = clock(); | |
#ifndef ONLINE_JUDGE | |
freopen("in.txt", "r", stdin); | |
freopen("out.txt", "w", stdout); | |
freopen("error.txt", "w", stderr); | |
#endif | |
//*/ | |
ll n,q; | |
cin >> n >>q; | |
map<string,ll>mp; | |
while(n--){ | |
string s; | |
ll w; | |
cin >> s >> w; | |
string str; | |
for(int i = 0; i< s.size(); i++){ | |
str += s[i]; | |
if(mp[str] == 0){ | |
mp[str] = w; | |
} | |
else{ | |
if(mp[str] < w) | |
mp[str] = w; | |
} | |
} | |
} | |
while(q--){ | |
string s; | |
cin >> s; | |
if(mp[s] == 0)cout << "-1\n"; | |
else cout << mp[s]<<endl; | |
} | |
//double end_time = clock(); | |
//printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment