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 ...
随机推荐
- jquety选择器
基本选择器 1.#id 根据id的属性值来获取元素 2.TagName 根据标签名来获取元素 3.selector1,selector2 匹配列表中的选择器(就是可以匹配多 ...
- ASP.NET应用程序的生命周期
对基于.Net平台的Web应用程序开发者来说,编写适合的应用程序生命周期的代码是非常重要的.所以必须要了解应用程序生命周期才能在适当的生命周期阶段编写合适代码,达到预期的效果.ASP.NET应用程序的 ...
- HDU 5773 The All-purpose Zero
这题想了1个多小时想不出来...方法真是精妙... 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的.因此我们可以把0拿出来,对剩下 的做O(nlogn)的LIS, ...
- 48、tensorflow入门二,线性模型的拟合
import tensorflow as tf import numpy as np#生成2维的100个0-1的随机数 x_data = np.float32(np.random.rand(2,100 ...
- 论深度优先(DFS)和广度优先搜索(BF)的优点及不足(更新ing)
例题: POJ 1915 Knight Moves 骑士遍历问题(跳马问题) 在一个m*m的棋盘上,从任意一个给定的位置(sx , sy)出发,为象棋中的马找一条路通过最少的步数到达另一位置(ex , ...
- PHP:var_dump展示不全
问题:var_dump展示不全,出现省略号 我们使用php的var_dump函数,可以更直观的查看输出结果,包括类型,数量等详细信息.此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值.数 ...
- Entity Framework 学习中级篇3—存储过程(中)
目前,EF对存储过程的支持并不完善.存在以下问题: l EF不支持存储过程返回多表联合查询的结果集. l EF仅支持返回返回某个表的全部字段,以便转换成对应的实体.无法 ...
- perl命令+关键字
来源: http://www.cnblogs.com/itech/archive/2012/11/01/2749666.html http://www.garybeene.com/vb/tut-per ...
- cordova环境配置步骤
1.安装node.js环境 官网: http://nodejs.org/ 2.sudo npm install -g cordova(一般会失败,需要用FQ安装或者用淘宝镜像安装,可以用FQ就可以不用 ...
- 有indexPath获取到cell对象
//SHSecretaryTipsCell *cell=(SHSecretaryTipsCell *)[tableView cellForRowAtIndexPath:indexPath];