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 ...
随机推荐
- 【codevs】1860 最大数
1860 最大数 题目描述 Description 设有n个正整数(n≤20),将它们联接成一排,组成一个最大的多位整数. 输入描述 Input Description 第一行一个正整数n. ...
- Python 学习笔记6
做人要有目标感! 继续学习Python哦.
- MySql 安装报错 :Last Error:Unable to update security. Access denied for user 'root'@'localhost(useing password:YES)
在网上查了一下,其实这个问题很好解决,. try again 然后current password mysql是默认密码为空,不要填,记住不要填就ok了
- wmts调用路径手工合成
wmts调用路径手工合成 一般OGC WMTS地图只提供了xml描述,地图应用常常要合成WMTS完整的调用URL.我们需要获知以下参数: BaseURL:例如 "http://10.36.5 ...
- selenium 百度登陆
using System;using OpenQA.Selenium;using OpenQA.Selenium.Firefox;//引用命名空间using System.IO; using Syst ...
- Handling Captcha | Webdriver
http://seleniumworks.blogspot.kr/2013/09/handling-captcha-webdriver.html Make use of the 'input' tag ...
- java中static关键字解析
static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大公司的面试官喜欢在面试时问到的知识点之一.下面就先讲述一下static关键字的用法和平常容易误解的地方,最后列 ...
- PHP:preg_replace
关于preg_match: http://www.cnblogs.com/helww/p/3466720.html 关于preg_match_all:暂时没有完整的 preg_replace_call ...
- jax-rs的客户端完整实例
本地接口: @Override public Response formsubGet(String accountContent, char inputContent, S ...
- java web服务器tomcat介绍【转载】
机器矩阵2016-08-10 22:14 java程序员亲切地称他为tom猫,看到这只猫可以说明1 服务器部署成功了 ,2 网络是联通的. 到底这只猫是什么来头呢? tomcat是Apache基金会下 ...