题意:DG在书店买书,从左到右第i本书价格为ai

DG从左走到右,能买就买。如果已知DG买了m本书,问他原本最多有多少钱。

若无上限,输出“Richman”,若不可能买这么多书,输出“Impossible”。

1 ≤ n ≤ 105,0 ≤ m ≤ n,0 ≤ ai ≤ 109

思路:价格为0的书必买,若价格为0的数量>m则无解

m=n则可以有无限钱

剩余的情况m减去价格为0的数量,剩余的一定是前m-1个和后面所有的最小值-1之和

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 110000
#define M 51
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1)
#define oo 1010000000 int a[N]; int main()
{
int cas;
scanf("%d",&cas);
for(int v=;v<=cas;v++)
{
int n,m;
scanf("%d%d",&n,&m);
int s=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if(!a[i]) s++;
}
if(s>m)
{
printf("Impossible\n");
continue;
}
if(n==m)
{
printf("Richman\n");
continue;
}
m-=s;
ll ans=;
int k=;
if(m>)
{
for(int i=;i<=n;i++)
{
if(a[i])
{
m--; ans+=a[i];
}
if(m==){k=i; break;}
}
}
int mn=oo;
for(int i=k+;i<=n;i++)
if(a[i]) mn=min(mn,a[i]);
ans+=mn-;
printf("%lld\n",ans);
}
return ;
}

【ZOJ4067】Books(贪心)的更多相关文章

  1. ZOJ4067 Books(贪心)

    题目链接:传送门 题目大意: DG在书店买书,从左到右第i本书价格为ai.DG从左走到右,能买就买.如果已知DG买了m本书,问他原本最多有多少钱.若无上限,输出“Richman”,若不可能买这么多书, ...

  2. HDU 5500 Reorder the Books 贪心

    Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  3. UVa 714 Copying books 贪心+二分 最大值最小化

    题目大意: 要抄N本书,编号为1,2,3...N, 每本书有1<=x<=10000000页, 把这些书分配给K个抄写员,要求分配给某个抄写员的那些书的编号必须是连续的.每个抄写员的速度是相 ...

  4. ZOJ 4067 - Books - [贪心][2018 ACM-ICPC Asia Qingdao Regional Problem J]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4067 题意: 给出 $n$ 本书(编号 $1 \sim n$), ...

  5. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  6. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  7. Codeforces 500C New Year Book Reading

    C. New Year Book Reading time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)

      Copying Books  Before the invention of book-printing, it was very hard to make a copy of a book. A ...

  9. uva 714 - Copying Books(贪心 最大值最小化 二分)

    题目描写叙述开头一大堆屁话,我还细致看了半天..事实上就最后2句管用.意思就是给出n本书然后要分成k份,每份总页数的最大值要最小.问你分配方案,假设最小值同样情况下有多种分配方案,输出前面份数小的,就 ...

随机推荐

  1. python中的文件操作小结1

    #!/usr/local/bin/python3 # -*- coding:utf-8 -*- f=open("test_1",'r',encoding="utf-8&q ...

  2. django-simple-captcha

    在注册页面生成验证码的时候,出现错误如下: build_attrs() takes from 1 to 2 positional arguments but 3 were given, 不知道为什么报 ...

  3. Nginx技术深入剖析

    Nginx软件功能模块说明 核心功能模块(Core functionality):主要对应配置文件的Main区块和Events区块. 标准的http功能模块: 企业 场景常用的Nginx http功能 ...

  4. 大话目标检测经典模型(RCNN、Fast RCNN、Faster RCNN)

      目标检测是深度学习的一个重要应用,就是在图片中要将里面的物体识别出来,并标出物体的位置,一般需要经过两个步骤:1.分类,识别物体是什么 2.定位,找出物体在哪里 除了对单个物体进行检测,还要能支持 ...

  5. Nginx 高级配置

    nginx官方网站:http://nginx.org/ 1.  Nginx连接后端的方式:反向代理(proxy_pass).直连fastcgi(fastcgi_pass) 例子: fastcgi_pa ...

  6. Weblogic Linux jar包安装

    环境/工具: 系统:CentOS 7 JDK:Oracle JDK fmw_12.2.1.2.0_wls.jar 0x01.新建普通用户weblogic 在Linux环境下建议使用普通用户安装,web ...

  7. com.squareup.okhttp.Interceptor

    retrift 集成了okhttp,所以,我们以后就不用再单独的引用http的jar 了. 但是,今天遇到一个问题,就是okhttp是这样设置一些intercept的: private static ...

  8. gVim的 设置

    在.vimrc中添加以下代码后,重启vim即可实现按TAB产生4个空格:set ts=4  (注:ts是tabstop的缩写,设TAB宽4个空格)set expandtab TAB替换为空格::set ...

  9. C# 6.0/7.0 的新特性

    转眼C#语言都已经迭代到7.0版本了,很多小伙伴都已经把C# 7.0 的新特性应用到代码中了,想想自己连6.0的新特性都还很少使用,今天特意搜集了一下6.0和7.0的一些新特性,记录一下,方便查阅. ...

  10. Pascal小游戏 不要消灭星星

    不要消灭星星 Pascal小游戏 Chaobs改编自pascal吧 控制台小游戏嘛,就当是练习一下结构化的写法. program wxtw; uses crt; type      zbdy=reco ...