Codeforces Round #374 (Div. 2) B. Passwords 贪心

B. Passwords

题目连接:

http://codeforces.com/contest/721/problem/B

Description

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

Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.

Sample Input

5 2

cba

abc

bb1

abC

ABC

abc

Sample Output

1 15

Hint

题意

有n个字符串,这个人从短的密码开始输入,如果密码长度相同,那就随便输出其中一个。

每当他输错k次的时候,就会暂停五秒。

问你最好情况下,他需要多少秒输对密码,最差情况呢

题解:

贪心一下就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n,k;
string s[maxn];
string ac;
bool cmp(string a,string b)
{
return a.size()<b.size();
}
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
cin>>s[i];
cin>>ac;
sort(s+1,s+1+n,cmp);
int ans = 0;
int ans1 = 0 ,ans2 = 0;
for(int i=1;i<=n;i++)
{
if(s[i].size()<ac.size())ans1++;
if(s[i].size()<=ac.size()&&ac!=s[i])ans2++;
}
cout<<1+ans1/k*5+ans1<<" "<<1+ans2/k*5+ans2<<endl;
}
上一篇:LinQ高级查询


下一篇:Codeforces Round #374 (Div. 2) A B C D 水 模拟 dp+dfs 优先队列