CodeForce 192D Demonstration
In the capital city of Berland, Bertown, demonstrations are against the recent election of the King of Berland. Berland opposition, led by Mr. Ovalny, believes that the elections were not fair enough and wants to organize a demonstration at one of the squares.
Bertown has n squares, numbered from 1 to n, they are numbered in the order of increasing distance between them and the city center. That is, square number 1 is central, and square number n is the farthest from the center. Naturally, the opposition wants to hold a meeting as close to the city center as possible (that is, they want an square with the minimum number).
There are exactly k (k < n) days left before the demonstration. Now all squares are free. But the Bertown city administration never sleeps, and the approval of an application for the demonstration threatens to become a very complex process. The process of approval lasts several days, but every day the following procedure takes place:
- The opposition shall apply to hold a demonstration at a free square (the one which isn't used by the administration).
- The administration tries to move the demonstration to the worst free square left. To do this, the administration organizes some long-term activities on the square, which is specified in the application of opposition. In other words, the administration starts using the square and it is no longer free. Then the administration proposes to move the opposition demonstration to the worst free square. If the opposition has applied for the worst free square then request is accepted and administration doesn't spend money. If the administration does not have enough money to organize an event on the square in question, the opposition's application is accepted. If administration doesn't have enough money to organize activity, then rest of administration's money spends and application is accepted
- If the application is not accepted, then the opposition can agree to the administration's proposal (that is, take the worst free square), or withdraw the current application and submit another one the next day. If there are no more days left before the meeting, the opposition has no choice but to agree to the proposal of City Hall. If application is accepted opposition can reject it. It means than opposition still can submit more applications later, but square remains free.
In order to organize an event on the square i, the administration needs to spend ai bourles. Because of the crisis the administration has only b bourles to confront the opposition. What is the best square that the opposition can take, if the administration will keep trying to occupy the square in question each time? Note that the administration's actions always depend only on the actions of the opposition.
The first line contains two integers n and k — the number of squares and days left before the meeting, correspondingly (1 ≤ k < n ≤ 105).
The second line contains a single integer b — the number of bourles the administration has (1 ≤ b ≤ 1018).
The third line contains n space-separated integers ai — the sum of money, needed to organise an event on square i (1 ≤ ai ≤ 109).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
Print a single number — the minimum number of the square where the opposition can organize the demonstration.
Examples
5 2
8
2 4 5 3 1
2
5 2
8
3 2 4 1 5
5
5 4
1000000000000000
5 4 3 2 1
5
Note
In the first sample the opposition can act like this. On day one it applies for square 3. The administration has to organize an event there and end up with 3 bourles. If on the second day the opposition applies for square 2, the administration won't have the money to intervene.
In the second sample the opposition has only the chance for the last square. If its first move occupies one of the first four squares, the administration is left with at least 4 bourles, which means that next day it can use its next move to move the opposition from any square to the last one.
In the third sample administration has a lot of money, so opposition can occupy only last square.
OJ-ID:
CodeForce 192D
author:
Caution_X
date of submission:
20191017
tags:
贪心
description modelling:
n个广场,每个广场都有相应的使用费,现在反对派有m天时间,政府有k块钱,反对派想要尽可能使用点数小的广场,现在反对派每天可以申请一个广场,政府则会用手上的钱租用这个广场(除非政府没钱或者这个广场是最后一个广场),问反对派可以拿到的最好的广场。
major steps to solve it:
(1).为了结果最优,假定反对派在最后一天到来之前都挑选最贵的广场
(2).到了最后一天:从广场1开始遍历,如果我们选择的这个广场在之前还没有被使用,那么这个广场就是最优广场,如果这个广场在之前已经被使用过了,那么我们就找找有没有还没有使用过的广场(序号偏后)可以替代这个广场。
AC code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[],b[];
bool cmp(ll a,ll b)
{
return a>b;
}
int main()
{
ll n,m,tot;
scanf("%lld%lld%lld",&n,&m,&tot);
for(int i=;i<=n;i++) {
scanf("%lld",&a[i]);
}
ll sum=;
for(int i=;i<n;i++) {
b[i]=a[i];
}
sort(b+,b+n,cmp);
for(int i=;i<m;i++) {
sum+=b[i];
}
for(int i=;i<=n;i++) {
if(a[i]>=b[m]) {
if(sum+b[m]>tot) {
printf("%d\n",i);
return ;
}
}
else if(sum+a[i]>tot){
printf("%d\n",i);
return ;
}
}
printf("%d\n",n);
return ;
}
CodeForce 192D Demonstration的更多相关文章
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 375_2_b_c
codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...
- codeforce 367dev2_c dp
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- 强连通分量&hdu_1269&Codeforce 369D
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...
- Demonstration of DB Query Analyzer 6.03 Installation and Running on Microsoft Windows 8
Demonstration of DB Query Analyzer 6.03 Installation and Running on Microsoft Windows 8 Ma Genfeng ( ...
- 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D
[树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...
随机推荐
- Springmvc配置定时任务注解开发
1.添加命名空间和xsd约束 xmlns:task="http://www.springframework.org/schema/task" http://www.springfr ...
- WebSocket数据加密——AES与RSA混合加密
前言 之前在写“一套简单的web即时通讯”,写到第三版的时候没什么思路,正好微信公众号看到一篇讲API交互加密,于是就自己搞了一套AES与RSA混合加密,无意中产生应用在WebSocket想法,好在思 ...
- Docker实用debug调试技巧锦集
阅读约 20 分钟 『重用』容器名 但我们在编写/调试Dockerfile的时候我们经常会重复之前的command,比如这种docker run --name jstorm-zookeeper zoo ...
- 怎么在CAD中测量图纸距离?来看看这两种方法
在CAD中设计图纸最重要的就是图纸的尺寸,俗话说也就是图纸间的距离.通过正确的数据设计出的图纸才能够准确,也能够避免施工时事不必要的误差.那怎么在CAD中测量图纸距离呢?具体要怎么来进行操作呢?下面我 ...
- 026.[转] 基于Docker及Kubernetes技术构建容器云平台 (PaaS)
[编者的话] 目前很多的容器云平台通过Docker及Kubernetes等技术提供应用运行平台,从而实现运维自动化,快速部署应用.弹性伸缩和动态调整应用环境资源,提高研发运营效率. 本文简要介绍了与容 ...
- python3+Scrapy爬虫使用pipeline数据保存到文本和数据库,数据少或者数据重复问题
爬取的数据结果是没有错的,但是在保存数据的时候出错了,出现重复数据或者数据少问题.那为什么会造成这种结果呢? 其原因是由于Spider的速率比较快,而scapy操作数据库操作比较慢,导致pipelin ...
- PHP转Go系列:字符串
字符串的赋值 在PHP中,字符串的赋值虽然只有一行,其实包含了两步,一是声明变量,二是赋值给变量,同一个变量可以任意重新赋值. $str = 'Hello World!'; $str = 'hia'; ...
- Mysql类
架构层面可以采用读写分离,主从复制等等,在数据库前端加cache,如memcache,用于用户登录,商品查询 1.mysql优化的原则是什么? 答: 1.mysql的优化首先要从设计表的过程中 ...
- 在Rust中,cargo使用国内镜像源
一个编程语言依赖包管理的普通问题. cargo解决得比较优雅. 一,新建$HOME/.cargo/config文件 [source.crates-io] registry = "https: ...
- 【洛谷P1963】[NOI2009]变换序列(二分图匹配)
传送门 题意: 现有一个\(0\)到\(n-1\)的排列\(T\),定义距离\(D(x,y)=min\{|x-y|,N-|x-y|\}\). 现在给出\(D(i, T_i)\),输出字典序最小的符合条 ...