二分查找。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std; const int maxn=+;
int n;
long long a[maxn],k;
vector<int>ans; bool check(long long m)
{
long long res=;
for(int i=;i<=n;i++) res=res+min(m,a[i]);
if(res>=k) return ;
return ;
} int main()
{
scanf("%d%lld",&n,&k);
for(int i=;i<=n;i++) scanf("%lld",&a[i]);
if(k==)
{
for(int i=;i<=n;i++) printf("%lld ",a[i]);
printf("\n");
return ;
}
long long l=,r=1e9, p=-;
while(l<=r)
{
long long mid=(l+r)/;
if(check(mid)) p=mid,r=mid-;
else l=mid+;
}
if(p==-) printf("-1\n");
else
{
long long sum=;
int pos;
for(int i=;i<=n;i++) sum=sum+min(a[i],p-);
for(int i=;i<=n;i++)
{
if(a[i]>=p) sum++;
if(sum==k) { pos=i; break; }
} for(int i=pos+;i<=n;i++) if(a[i]>=p) ans.push_back(i);
for(int i=;i<=pos;i++) if(a[i]>=p+) ans.push_back(i); for(int i=;i<ans.size();i++) printf("%d ",ans[i]);
printf("\n"); }
return ;
}

CodeForces 83B Doctor的更多相关文章

  1. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  2. Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力

    C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...

  3. Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)

    A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  4. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  5. Average Sleep Time CodeForces - 808B (前缀和)

    It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, on ...

  6. codeforces 586B/C

    题目链接:http://codeforces.com/contest/586/problem/B B. Laurenty and Shop time limit per test 1 second m ...

  7. Codeforces Round #345 (Div. 1) A - Watchmen 容斥

    C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...

  8. Watchmen CodeForces - 650A

    Watchmen CodeForces - 650A Watchmen are in a danger and Doctor Manhattan together with his friend Da ...

  9. 【16.23%】【codeforces 586C】Gennady the Dentist

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. mysql的存储引擎如何选择

    myisam:如果表对事务要求不高,用时以查询和添加为主,我们考虑myisam存储,如bbs中的发帖表.回复表 innodb:对事务要求高,保存的数据都是重要的数据,我们建议使用innodb,比如订单 ...

  2. ural 1203. Scientific Conference(动态规划)

    1203. Scientific Conference Time limit: 1.0 second Memory limit: 64 MB Functioning of a scientific c ...

  3. Get和Post请求的区别

    Get:组拼url的方式,提交数据到服务器,url最大长度不能超过4K; Post:直接浏览器把数据写给服务器,流的形式.

  4. ios电话拨打进行监听电话状态

    #import "ViewController.h" #import <CoreTelephony/CTCallCenter.h> #import <CoreTe ...

  5. CentOS ulimit

    Linux 文件系统设置 文件句柄数 ulimit -n 查看 echo "* - nofile 65536" >> /etc/security/limits.conf ...

  6. ueditor浏览器 无法上传文件.问题

    dll也都引用了 路径绝对tmd没问题 最后 我一点一点的调试发现了问题 草tmd百度程序员 */UE.ajax = function() { //创建一个ajaxRequest对象 var fnSt ...

  7. window.open弹出窗口调用controller

    前台图片调用js函数 <img src='${pageContext.request.contextPath}/FlatUI/img/link.png' id='report' alt='&qu ...

  8. 使用SQL Server 2000索引视图提高性能

    什么是索引视图? 许多年来,Microsoft? SQL Server? 一直都提供创建虚拟表(称为视图)的功能.在过去,这些视图主要有两种用途: 提供安全机制,将用户限制在一个或多个基表中的数据的某 ...

  9. php5.6之后的版本使用curl以@+文件名的方式上传文件无效的解决版本

    使用curl上传文件使用file=@文件路径的方式,在php5.6以后的版本中无法使用了 官方文档给出明确解释 如果需要支持的话,可以将CURLOPT_SAFE_UPLOAD设置为false 或者使用 ...

  10. QT插件和服务培训

    下载地址:http://files.cnblogs.com/files/senior-engineer/%E6%8F%92%E4%BB%B6%E5%92%8C%E6%9C%8D%E5%8A%A1%E5 ...