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 ;
}
Codeforces Round #270 1002的更多相关文章
- Codeforces Round #270 1003
Codeforces Round #270 1003 C. Design Tutorial: Make It Nondeterministic time limit per test 2 second ...
- Codeforces Round #270 1001
Codeforces Round #270 1001 A. Design Tutorial: Learn from Math time limit per test 1 second memory l ...
- Codeforces Round #270 A~D
Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...
- Codeforces Round #270(利用prim算法)
D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...
- codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)
题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...
- 多种方法过Codeforces Round #270的A题(奇偶法、打表法和Miller_Rabin(这个方法才是重点))
题目链接:http://codeforces.com/contest/472/problem/A 题目: 题意:哥德巴赫猜想是:一个大于2的素数一定可以表示为两个素数的和.此题则是将其修改为:一个大于 ...
- Codeforces Round #270 D Design Tutorial: Inverse the Problem --MST + DFS
题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否 ...
- Codeforces Round #270 D C B A
谈论最激烈的莫过于D题了! 看过的两种做法不得不ORZ,特别第二种,简直神一样!!!!! 1th:构造最小生成树. 我们提取所有的边出来按边排序,因为每次我们知道边的权值>0, 之后每次把边加入 ...
- Codeforces Round #270
A 题意:给出一个数n,求满足a+b=n,且a+b均为合数的a,b 方法一:可以直接枚举i,n-i,判断a,n-i是否为合数 #include<iostream> #include< ...
随机推荐
- UVa 11998 Broken Keyboard (数组模拟链表问题)
题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int m ...
- 导入.pch文件
Xcode5中创建一个工程的时候,系统会自动创建一个以以工程名为名字的pch(Precompile Prefix Header)文件,开发的过程中可以将广泛使用的头文件以及宏包含在该文件下,编译器就会 ...
- 屠蛟之路_蛟灵岛战役(上)_SixthDay
乘风破浪,屠蛟少年们终于到达beta怪蛟大boss的老巢--蛟灵岛. 这是一座孤立在东海深处的荒岛,岛上黑烟缭绕.瘴气重重,屠蛟少年们一登岛,就感受到浓浓的腥味和妖气. 果然,再小心翼翼,走两步居然陷 ...
- 十分钟入门less(翻译自:Learn lESS in 10 Minutes(or less))
十分钟入门less(翻译自:Learn lESS in 10 Minutes(or less)) 注:本文为翻译文章,因翻译水平有限,难免有缺漏不足之处,可查看原文. 我们知道写css代码是非常枯燥的 ...
- js006-面向对象的程序设计
js006-面向对象的程序设计 面向对象(Object-Oriented,OO)的语言有一个标志,那就是他们都有类的概念.而通过类可以创建多个具有相同属性和方法的对象. ECMA-262把对象定义为: ...
- 转换流——OutputStreamWriter类与InputStreamReader类
字节流和字符流的转换类 OutputStreamWriter:是Writer的子类,将输出的字符流变成字节流 InputStreamReader:是Reader的子类,将输入的字节流变成字符流 将字节 ...
- 使用github和hexo搭建博客
title: How to build your blog by Hexo in github Welcome to huihuang's blog,you will find what you ex ...
- Linux环境下常用软件(个人笔记编辑更改中)
近期使用CentOS,就在这里记录一下.首先,个人版本是CentOS6.5,属于centos系列,Fedora系列的理论上也可以用. 工欲善其事,必先利其器,这里介绍我的软件包配置: 1.vim(增强 ...
- ElasticSearch之二——集群
ElasticSearch 集群 首先看下ElasticSearch(ES)的架构: 术语解释: cluster:代表一个集群,集群中有多个节点,其中有一个master节点,master通过选举自动产 ...
- VC亲自教你写BP
2015年5月24日下午,腾讯开放平台“创业ABC”沙龙在腾讯众创空间(上海)举行.活动以“创业融资实战——从计划书到如何估值到如何花钱”为主题,险峰华兴投资负责人徐建海先生现场分享<如何写BP ...