题目:

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. pl/sql 实例精解 05

    本章主要讨论 case 语句 1: case [SELECTOR] 2: when expression 1 then statement 1; 3: when expression 2 then s ...

  2. js移除某一类的div

    (转载)Javascript removeChild()不能删除全部子节点的解决办法   在Javascript中,只提供了一种删除节点的方法:removeChild().removeChild() ...

  3. bootstrap基础学习九篇

    现在学学bootstrap响应式实用工具 Bootstrap 提供了一些辅助类,以便更快地实现对移动设备友好的开发.这些可以通过媒体查询结合大型.小型和中型设备,实现内容对设备的显示和隐藏. 需要谨慎 ...

  4. 详略。。设计模式2——单例变形(多例).。。。studying

    ★ 缓存在单例中的使用("单例+缓存"技术) 缓存在编程中使用非常频繁,有着非常关键的数据,它可以帮助程序实现以空间换取时间, 通常被设计成整个应用程序所共享的一个空间,现要求实现 ...

  5. Nucleus PLUS简单介绍

    近些年来,随着嵌入式系统飞速的发展,嵌入式实时操作系统广泛地应用在制造工业.过程控制.通讯.仪器仪表.汽车.船舶.航空航天.军事.装备.消费类产 品等方面.今天嵌入式系统带来的工业年产值超过了1万亿美 ...

  6. linux more less cat

    在使用和维护Linux系统时,常常需要查看文件的相关内容,那么如何才能做到呢?下面小编就以CentOS6.4系统为例演示查看文件内容的几种常用的方法. 工具/原料   CentOS6.4 查看文件内容 ...

  7. win10 更新导致 VisualSVN 报0x80041024错错误

    主要是WMI丢失,重新注册下就好. 运行cmd.exe, 运行语句:mofcomp "%VISUALSVN_SERVER%WMI\VisualSVNServer.mof" 修复即可 ...

  8. django用户认证系统——重置密码7

    当用户不小心忘记了密码时,网站需要提供让用户找回账户密码的功能.在示例项目中,我们将发送一封含有重置用户密码链接的邮件到用户注册时的邮箱,用户点击收到的链接就可以重置他的密码,下面是具体做法. 发送邮 ...

  9. 一个Demo展示Storyboard的强大

    本文转载至http://www.cocoachina.com/ios/20150330/11440.html 今天我通过完成一个长按cell删除的Demo,向你们展示熟练运用storyboard和Au ...

  10. 清空select下拉框的方法

    $("#search").find("option").remove(); //或者 $("#search").empty();