Codeforces Round #270 1002

Codeforces Round #270 1002

B. Design Tutorial: Learn from Life

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.

Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following way. We have n people standing on the first floor, the i-th person wants to go to the fi-th floor. Unfortunately, there is only one elevator and its capacity equal to k (that is at most k people can use it simultaneously). Initially the elevator is located on the first floor. The elevator needs |a - b| seconds to move from the a-th floor to the b-th floor (we don't count the time the people need to get on and off the elevator).

What is the minimal number of seconds that is needed to transport all the people to the corresponding floors and then return the elevator to the first floor?

Input

The first line contains two integers n and k(1 ≤ n, k ≤ 2000) — the number of people and the maximal capacity of the elevator.

The next line contains n integers: f1, f2, ..., fn(2 ≤ fi ≤ 2000), where fi denotes the target floor of the i-th person.

Output

Output a single integer — the minimal time needed to achieve the goal.

Sample test(s)

Input

3 2 
2 3 4

Output

8

Input

4 2 
50 100 50 100

Output

296

 
爬楼梯,贪心思想,从最大的层数考虑
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int N,M;
struct node
{
int str;
bool operator < (const node &rhs) const
{
return str>rhs.str;
}
}num[]; int main()
{
scanf("%d%d",&N,&M);
for(int i = ;i<N;i++)
{
scanf("%d",&num[i].str);
}
sort(num,num+N);
int t = N/M;
if(N%M!=) t+=;
//cout<<t<<endl;
int ans = ;
for(int i = ;i<t;i++)
{
ans+=*(num[i*M].str-);
}
printf("%d\n",ans);
return ;
}
上一篇:asp.net中缓存的使用介绍一


下一篇:玩转Chrome workplace