superoj738 诸葛亮
来源:互联网 发布:暴力美学电影 知乎 编辑:程序博客网 时间:2024/06/09 19:44
题目:
输入格式
第一行包含一个整数 n,k。
接下来一行,包括 n 个整数,第 i 个数是 v[i]。
输出格式
输出共 k 行,每行包括一个整数,第 i 行的数表示第 i 大的收益。
样例数据 1
输入 [复制]
5 2
1 2 -1 -1 3
输出
4
3
备注
【数据范围】
对于 10% 的数据,1≤n≤200。
对于 30% 的数据,1≤n≤2000。
对于 50% 的数据,1≤n≤100000,1≤k≤1000。
对于 100% 的数据,1≤n≤100000,1≤k≤n,-1000≤v[i]≤1000。
分析:
抓住性质收益为绝对值,这就好写了
随便求出前缀和,升序,降序sort,max-min一定是最优(因为是绝对值,顺序不重要)
然后用堆(queue) 采用先多加后少加 来去重添加入堆即可
#include<string>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<queue>#include<vector>using namespace std;int hemin[100010];int hemax[100010];int a[100010];int n,m;bool comp(const int &a,const int &b){return a>b;}struct node{ int a,b,c; bool operator < (const node &t)const { return c<t.c; }};priority_queue <node> q;int main(){ //freopen("zhugeliang.in","r",stdin); // freopen("zhugeliang.out","w",stdout); int i,j,k; scanf("%d%d",&n,&m); for(i=1;i<=n;i++) { scanf("%d",&a[i]); hemin[i]=hemin[i-1]+a[i]; hemax[i]=hemin[i];} sort(hemin,hemin+1+n); sort(hemax,hemax+1+n,comp); j=0; k=0; //max node hehe,mn; for(i=0;i<=n;i++) { int dd=hemax[i]-hemin[0]; hehe.c=dd; hehe.a=i; hehe.b=0; q.push(hehe); } int aa,bb; for(i=1;i<=m;i++) { mn=q.top(); q.pop(); aa=mn.a; bb=mn.b; printf("%d\n",mn.c); int dd=hemax[mn.a]-hemin[mn.b+1]; hehe.c=dd; hehe.a=mn.a; hehe.b=mn.b+1; q.push(hehe); } return 0;}
0 0
- superoj738 诸葛亮
- 诸葛亮
- 神人诸葛亮
- 诸葛亮:卧龙
- 《戒子篇》-- 诸葛亮
- 诸葛亮《诫子篇》
- 关于诸葛亮
- 出师表 诸葛亮
- 诸葛亮娶丑妻
- 诸葛亮骂死王朗
- 诸葛亮--舌辩群儒
- 《戒子训》 诸葛亮
- 诸葛亮《戒子篇》
- 追悼诸葛亮
- 诸葛亮兵书
- 2015062001 - 诸葛亮
- 诸葛亮兵法
- 诸葛亮的《戒子篇》
- 白盒测试和黑盒测试
- spring FactoryBean
- redis 主从切换
- django用apache+mod_wsgi部署后中文乱码的解决方法
- 图像质量评价:SSIM&PSNR
- superoj738 诸葛亮
- linux-inode(yfruan)
- NET转JAVA学习二(学习计划)
- 软件开发(2):软件开发工程师常用的工具软件
- 浅析Java内存和创建对象时成员的初始化过程
- NYOJ 252 01串(dp,递推)
- POJ 3190 Stall Reservations (选择不相交区间)
- XAMPP for MAC 安装后MYSQL不能正常启动的解决办法
- 依赖关系 、关联关系