CodeForces 83B Doctor
二分查找。
#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的更多相关文章
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- codeforces 586B/C
题目链接:http://codeforces.com/contest/586/problem/B B. Laurenty and Shop time limit per test 1 second m ...
- Codeforces Round #345 (Div. 1) A - Watchmen 容斥
C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...
- Watchmen CodeForces - 650A
Watchmen CodeForces - 650A Watchmen are in a danger and Doctor Manhattan together with his friend Da ...
- 【16.23%】【codeforces 586C】Gennady the Dentist
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- KeyTweak(笔记本键盘设置工具) V2.20 中文版
软件名称: KeyTweak(笔记本键盘设置工具)软件语言: 简体中文授权方式: 免费软件运行环境: Win 32位/64位软件大小: 50KB图片预览: 软件简介:KeyTweak 通过设置系统的注 ...
- HTTPS科普扫盲帖【转】
为什么需要https HTTP是明文传输的,也就意味着,介于发送端.接收端中间的任意节点都可以知道你们传输的内容是什么.这些节点可能是路由器.代理等. 举个最常见的例子,用户登陆.用户输入账号,密码, ...
- 灰色关联度Matlab代码
load x.txt %把原始数据存放在纯文本文件x.txt中,其中把数据的"替换替换成. for i=1:40x(i,:)=x(i,:)/x(i,1); %标准化数据end data=x; ...
- 2016-11-10linux
---恢复内容开始--- 新建用户natasha,uid为88,gid为6,备注信息为"master" 修改natasha用户的家目录为/Natasha 查看用户信息配 ...
- jquery各版本区别
jquery版本区别: 1.3一般功能够 1.4.2一般功能够而且稳定 1.7+比较新特性 2不支持老IE 兼容的话最好选 1.x.稳定性就用1.7或者1.4,其中1.4的体积相对 ...
- jQuery实现的简单分页功能的详细解析
分页功能在项目开发中不可或缺,老司机操作起来就和呼吸一样简单,新手恐怕就会吃力一些. 今天我回顾了一下具体的操作步骤,决定详细的分析一下每一步的实现目的及原理. 我们会创建一个简单的json文件来模拟 ...
- C# 连接SQL Server数据库的几种方式--server+data source等方式
如何使用Connection对象连接数据库? 对于不同的.NET数据提供者,ADO.NET采用不同的Connection对象连接数据库.这些Connection对象为我们屏蔽了具体的实现细节,并提供了 ...
- hdu_5777_domino(贪心)
题目链接:hdu_5777_domino 题意: 小白在玩一个游戏.桌子上有n张多米诺骨牌排成一列.它有k次机会,每次可以选一个还没有倒的骨牌,向左或者向右推倒.每个骨 牌倒下的时候,若碰到了未倒下的 ...
- 前台改变asp button控件的值,后台取值没有改变的问题
前台: <asp:Button ID="btnEdit" Style="margin-left: 600px;" runat="server&q ...
- 得到root,并且获取密码
第一次使用ubuntu的时候 先使用这个命令 sudo passwd root 然后就可以改密码了