codeforces 721 Passwords

来源:互联网 发布:php连接数据库语句 编辑:程序博客网 时间:2024/05/20 06:30
B. Passwords
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.

Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.

Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.

Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.

The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.

The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.

Output

Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.

Examples
input
5 2cbaabcbb1abCABCabc
output
1 15
input
4 10011221222
output
3 4
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){int n,k;char mima[110];int a[110];while(~scanf("%d%d",&n,&k)){for(int i = 0; i <= n; i++){memset(mima,'\0',sizeof(mima));scanf("%s",mima);a[i] = strlen(mima);}sort(a,a+n);int t = lower_bound(a,a+n,a[n]) - a;int e = upper_bound(a,a+n,a[n]) - a;int min_T = 0,max_T = 0;min_T = t / k * 5 + (t + 1);max_T = (e - 1) / k * 5 + e;printf("%d %d\n",min_T,max_T);}return 0;}


0 0
原创粉丝点击