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 ...
随机推荐
- python初识1
作者:武沛齐 出处:http://www.cnblogs.com/wupeiqi/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接. 安装Pyt ...
- json处理三部曲之第三曲:利用Gson处理json
需要导入gson-xxx.jar包 <dependency> <groupId>com.google.code.gson</groupId> <artifac ...
- windows下更新python报错permission denied
注意退出所有python进程,可能是在使用中导致权限不足以删除
- PHP修改记录
1. Http请求错误--20151123 参考网址:http://www.lvtao.net/dev/php-nginx-uploadfiy.html 是配置问题,修改php.ini文件: uplo ...
- MFC利用ADO建立access数据源 ---包括访问带access密码与不带access密码两种方式)
void CDlg_login::OnButton1() { CString c_user,c_password;m_user1.GetWindowText(c_user);m_password1.G ...
- php file取重复
function FetchRepeatMemberInArray($array) { // 获取去掉重复数据的数组 $unique_arr = array_unique ( $array ); // ...
- 大数据量情况下求top N的问题
上周五的时候去参加了一个面试,被问到了这个问题.问题描述如下: 假如存在一个很大的文件,文件中的每一行是一个字符串.请问在内存有限的情况下(内存无法加载这个文件中的所有内容),如何计算出出现频率最高的 ...
- Golang:测试map是否存在
请看这个url:http://www.du52.com/text.php?id=561 if v, ok := m1["a"]; ok { fmt.Println(v) } els ...
- restlet上传图片代码
客户端用的是 jquery file upload, 服务器端用的是restlet package org.soachina.rest.component.resource; import java. ...
- angular、bootstrap初稿搭建
1.bootstrap3.0中,ie8不兼容响应式设计 @media,需要添加如下2个查件 <!-- html5.js for IE less than 9 --> <!-- ...