URAL 1901 Space Elevators(贪心)
来源:互联网 发布:阿里云的黑洞模式 编辑:程序博客网 时间:2024/06/08 09:32
1901. Space Elevators
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
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 ≤ 105; 1 ≤ s ≤ 109). The second line contains integers v1, …, vn that are the importance of the employees (1 ≤ vi ≤ 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.
Sample
6 61 2 3 3 4 5
52 5 1 3 4 3
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int a[100010],b[100010];int main(){int n,s,i,c,sum,ans,l,r;while(~scanf("%d%d",&n,&s)){memset(b,0,sizeof(b));for(i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);l=0;r=n-1;c=0;while(l<r){if(a[l]+a[r]>s){b[c++]=a[l++];b[c++]=a[r--];}else{b[c++]=a[l++];b[c++]=a[l++];}}if(l==r)b[c++]=a[l];sum=0;for(i=0;i<c;i++){sum++;if(b[i]+b[i+1]<=s)i++;}printf("%d\n%d",sum,b[0]);for(i=1;i<n;i++)printf(" %d",b[i]);printf("\n");} return 0;}
0 0
- URAL 1901 Space Elevators(贪心)
- URAL 1901 Space Elevators (苦逼水题,2级)
- BNUOJ26429 Space Elevators(贪心)
- URAL 1775 Space Bowling
- ural 1820. Ural Steaks 贪心
- URAL 1389 Roadworks 贪心
- URAL 1826. Minefield 贪心
- Ural 2041 Nanomatryoshkas(贪心)
- Google top 10 crazy projects: from Driverless Cars to Elevators to Space (Picture)
- URAL 1820 Ural Steaks (贪心)
- Elevators UVALive
- Elevators UVALive
- ural 1303 Minimal Coverage【贪心】
- URAL 1303. Minimal Coverage 贪心
- URAL 2041 Nanomatryoshkas(贪心)
- URAL 1203 Scientific Conference (贪心)
- URAL 1303 Minimal Coverage (贪心)
- URAL 1826 贪心经典题型
- android 自定义View之Path
- jsp 弹出窗口设置大全
- js 字符串转换数字
- view详解(二) view的绘制流程
- C++数据类型
- URAL 1901 Space Elevators(贪心)
- OCP 1Z0 053 163
- 字符数组
- Java hascode()
- java 基本数据类型及自动类型提升
- 类模板详解
- 黑马程序员--浅复制与深复制
- 算法导论 chapter 10.1 Page233 Stack push and pop
- JQuery上传插件Uploadify使用详解