题目:

Nowadays spaceships are never launched from the Earth's surface. There is a huge spaceport placed in the geostationary orbit and connected to the Earth with carbon nanotube cables. People and cargo are delivered to the orbit by elevators moving along these cables. It turned out that the space elevator is much more comfortable and cheaper than a spaceship.
Tomorrow a group of key employees of the “Akross” corporation will go to the spaceport with a secret mission. The spaceport management has reserved a special double elevator for the group. The Head of “Akross” demanded that at any given time the total importance of staff in the elevator must not exceed some fixed value. Under this condition, even in case of fatal accident the corporation will be able to recover. Employees enter the elevator in turns. The elevator is sent up if two people entered, or if only one person entered and the following person behind him is so significant for the corporation that it is impossible to send them together in one elevator.
The spaceport management wants to know the maximum number of elevator runs required to deliver all employees, so the right amount of oxygen cylinders and charged batteries can be prepared in advance.

Input

The first line contains integers n and s that are the amount of employees of “Akross” assigned to the mission, and the maximum total importance of two employees which can go together in the elevator (1 ≤ n ≤ 10 5; 1 ≤ s ≤ 10 9). The second line contains integers v 1, …, v n that are the importance of the employees (1 ≤ v i ≤ s).

Output

In the first line output the maximum amount of trips of the elevator. In the second line output the importance of staff in order from the first employee in the line to the last, for which the elevator will do this amount of trips. If there are several possible answers, output any of them.

Example

input output
6 6
1 2 3 3 4 5
5
2 5 1 3 4 3

思路:先排序,然后贪心的选人获得最大运行次数。

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,mx,v[],vis[],ans[];
int main(void)
{
scanf("%d%d",&n,&mx);
for(int i=;i<=n;i++)
scanf("%d",&v[i]);
sort(v+,v++n);
int sum=,l=,r=n;
while(l<r)
{
while(l<r && v[l]+v[r]<=mx) l++;
if(l>=r)break;
ans[sum++]=v[l],vis[l++]=;
ans[sum++]=v[r],vis[r--]=;
}
for(int i=n;i;i--)if(!vis[i])
ans[sum++]=v[i];
sum=;
for(int i=;i<=n;i++)
if(ans[i]+ans[i+]>mx)sum++;
else sum++,i++;
printf("%d\n",sum);
for(int i=;i<=n;i++)
printf("%d ",ans[i]);
return ;
}

URAL - 1901 Space Elevators的更多相关文章

  1. URAL 2099 Space Invader题解 (计算几何)

    啥也不说了,直接看图吧…… 代码如下: #include<stdio.h> #include<iostream> #include<math.h> using na ...

  2. ural 1075. Thread in a Space

    1075. Thread in a Space Time limit: 1.0 secondMemory limit: 64 MB There are three points in a 3-dime ...

  3. URAL 1775 B - Space Bowling 计算几何

    B - Space BowlingTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  4. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  5. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  6. ural 2065. Different Sums

    2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...

  7. ural 1249. Ancient Necropolis

    1249. Ancient Necropolis Time limit: 5.0 secondMemory limit: 4 MB Aerophotography data provide a bit ...

  8. ural 1072. Routing

    1072. Routing Time limit: 1.0 secondMemory limit: 64 MB There is a TCP/IP net of several computers. ...

  9. ural 1071. Nikifor 2

    1071. Nikifor 2 Time limit: 1.0 secondMemory limit: 64 MB Nikifor has a number x. He doesn't need it ...

随机推荐

  1. 什么是 AJAX ?

    什么是 AJAX ? AJAX = 异步 JavaScript 和 XML. AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味 ...

  2. Java 的数组

    几乎所有程序设计语言都支持数组.在C和 C++里使用数组是非常危险的,因为那些数组只是内存块.若程 序访问自己内存块以外的数组,或者在初始化之前使用内存(属于常规编程错误),会产生不可预测的后果 (注 ...

  3. JavaWeb——过滤器

    过滤器简介 WEB过滤器是一个服务器端的组件,它可以截取用户端的请求与相应信息,并对这些信息过滤. 过滤器的工作原理和生命周期 在没有Web过滤器的情况下,用户直接访问服务器上的Web资源.但是如果存 ...

  4. java web 页面提速

    记得面试现在这份工作的时候,一位领导语重心长地谈道——当今的世界是互联网的世界,IT企业之间的竞争是很激烈的,如果一个网页的加载和显示速度,相比别人的站点页面有那么0.1秒的提升,那也是很大的一个成就 ...

  5. node中的require和exports

    http://cnodejs.org/topic/4f16442ccae1f4aa270010e9

  6. 把xml格式的字符串写入到一个xml文件中

    package demo; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; impo ...

  7. RecyclerView上拉隐藏Toolbar,下拉显示

    RecyclerView下拉隐藏Toolbar,上拉显示效果图 先说个事:最近我准备做个开源的博客园android客户端!符合Google最新的material design设计风格的!不知道有没有小 ...

  8. JZOJ.5230【NOIP2017模拟8.5】队伍统计

    Description 现在有n个人要排成一列,编号为1->n .但由于一些不明原因的关系,人与人之间可能存在一些矛盾关系,具体有m条矛盾关系(u,v),表示编号为u的人想要排在编号为v的人前面 ...

  9. 【BZOJ3798】特殊的质数 分块打表

    [BZOJ3798]特殊的质数 Description 求[A,B]之间的质数个数,并且满足X=Q^2+P^2,P,Q是正整数. Input 第一行输入A,B Output 输出有多少组P,Q满足条件 ...

  10. No transactional EntityManager available; nested exception is javax.persistence.TransactionRequiredException: No transactional EntityManager available

    参考地址:http://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/ ...