C. Sagheer and Nubian Market
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different
items numbered from 1 to n.
The i-th item has base cost ai Egyptian
pounds. If Sagheer buys k items with indices x1, x2, ..., xk,
then the cost of item xj is axj + xj·k for 1 ≤ j ≤ k.
In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k.

Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more
than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?

Input

The first line contains two integers n and S (1 ≤ n ≤ 105 and 1 ≤ S ≤ 109) —
the number of souvenirs in the market and Sagheer's budget.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 105) —
the base costs of the souvenirs.

Output

On a single line, print two integers kT —
the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs.

Examples
input
3 11
2 3 5
output
2 11
input
4 100
1 2 5 6
output
4 54
input
1 7
7
output
0 0
Note

In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28.
If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.

In the second example, he can buy all items as they will cost him [5, 10, 17, 22].

In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it.

————————————————————————————————————

题目的意思是给出n件商品价格和一个最大限额S,购买时商品的价格变为axj + xj·k,xj是

下标索引,k是购买数量,求最多能买几件和花费

思路:二分+验证,二分购买的数量,验证时按数量计算价格排序

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath> using namespace std; #define LL long long
const int inf=0x7fffffff;
int n;
LL s;
LL a[100005];
LL b[100005]; bool ok(int x)
{
for(int i=0; i<n; i++)
{
b[i]=a[i]+(LL)(i+1)*x;
}
sort(b,b+n);
LL sum=0;
for(int i=0; i<x; i++)
sum+=b[i];
if(sum<=s)
return 1;
return 0;
} int main()
{
while(~scanf("%d%d",&n,&s))
{
for(int i=0; i<n; i++)
scanf("%lld",&a[i]);
int l=1,r=n;
int ans=0;
while(l<=r)
{
int mid=(l+r)>>1;
if(ok(mid)) l=mid+1,ans=mid;
else r=mid-1;
}
for(int i=0; i<n; i++)
{
b[i]=a[i]+(LL)(i+1)*ans;
}
sort(b,b+n);
LL sum=0;
for(int i=0; i<ans; i++)
sum+=b[i];
printf("%d %lld\n",ans,sum);
} return 0;
}

Codeforces812C Sagheer and Nubian Market 2017-06-02 20:39 153人阅读 评论(0) 收藏的更多相关文章

  1. Codeforces812B Sagheer, the Hausmeister 2017-06-02 20:47 85人阅读 评论(0) 收藏

    B. Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. Codeforces812A Sagheer and Crossroads 2017-06-02 20:41 139人阅读 评论(0) 收藏

    A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input sta ...

  3. Python获取当前时间 分类: python 2014-11-08 19:02 132人阅读 评论(0) 收藏

    Python有专门的time模块可以供调用. <span style="font-size:14px;">import time print time.time()&l ...

  4. HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏

    Easy Summation                                                             Time Limit: 2000/1000 MS ...

  5. 2014/11/06 Oracle触发器初步 2014-11-06 09:03 49人阅读 评论(0) 收藏

    触发器我就不多解释了,保证数据的完整性的神器,嗯..也是减少程序员工作托管给数据库操作的好帮手.就不讲一些大道理了.通俗点,我们对数据库的操作,无非就是增 删 改 查. 触发器就是在删,改,增的时候( ...

  6. hdu 1082, stack emulation, and how to remove redundancy 分类: hdoj 2015-07-16 02:24 86人阅读 评论(0) 收藏

    use fgets, and remove the potential '\n' in the string's last postion. (main point) remove redundanc ...

  7. NPOI 通用导出数据到Excel 分类: C# Helper 2014-11-04 16:06 246人阅读 评论(0) 收藏

    应用场景: 在项目中,经常遇到将数据库数据导出到Excel,针对这种情况做了个程序封装.工作原理:利用NPOI将SQL语句查询出的DataTable数据导出到Excel,所见即所得. 程序界面:   ...

  8. cloud theory is a failure? 分类: Cloud Computing 2013-12-26 06:52 269人阅读 评论(0) 收藏

    since LTE came out, with thin client cloud computing  and broadband communication clouding 不攻自破了.but ...

  9. leetcode N-Queens/N-Queens II, backtracking, hdu 2553 count N-Queens, dfs 分类: leetcode hdoj 2015-07-09 02:07 102人阅读 评论(0) 收藏

    for the backtracking part, thanks to the video of stanford cs106b lecture 10 by Julie Zelenski for t ...

随机推荐

  1. 对于读txt文件一点总结

    txt 内容 中间有比如如空格,制表符(tab)在txt为空格符(Spaces).回车符.换行符,有空字符串等情况,在读取过滤中要充分考虑到 1:打开文件 var sr=new StreamReade ...

  2. 1.Mysql的安装与配置

    1.Mysql的安装与配置1.1 Mysql的下载 mysql是开源数据库,开源数据库在中低端应用中占据了很大的市场份额. mysql社区版自由下载而且安全免费,官方不提供任何技术支持,适用于普通用户 ...

  3. 4. 深入 Python 流程控制

    除了前面介绍的 while 语句,Python 还从其它语言借鉴了一些流程控制功能,并有所改变. 4.1. if 语句 也许最有名的是 if 语句.例如: >>> x = int(i ...

  4. win7系统 无线上网卡 共享网络,设置成wifi热点

    给家人买了一个新的智能手机,用的移动神州行套餐,没有开通3G,想更新一些应用软件,于是想到能不能用电脑上的无线上网卡. 在网上找到了一方法,试了一下,还真是可以. 步骤如下: 用无线上网卡拨号上网,并 ...

  5. Win10传递优化设置技巧

    什么是“传递优化缓存” “传递优化”是微软为了加快Windows更新和Microsoft Store应用更新的下载速度,而在Windows10中引入的一种“自组织分布式本地化缓存”设计,可以在用户电脑 ...

  6. 差异表达分析之FDR

    差异表达分析之FDR 随着测序成本的不断降低,转录组测序分析已逐渐成为一种很常用的分析手段.但对于转录组分析当中的一些概念,很多人还不是很清楚.今天,小编就来谈谈在转录组分析中,经常会遇到的一个概念F ...

  7. Ubuntu12.04软件安装指南

    更新升级源 首先编辑软件源,在终端输入下面命令: sudo gedit /etc/apt/sources.list 较快速的升级源有163,台湾源,科大源,搜狐源等,大家将新的升级源全部覆盖原文件so ...

  8. Spring IOC(四)FactoryBean

    Spring IOC(四)FactoryBean Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一般情况下,Spring ...

  9. linux 常用命令(三)ssh

    linux 常用命令(三)SSH 一.SSH 安装及免密登陆 (1) SSH 安装并配置 CentOS 默认已安装了 SSH client.SSH server,打开终端执行如下命令进行检验 rpm ...

  10. [规则原则定理]规则原则定理章1CAP原则

    CAP原则又称CAP定理,指的是在一个分布式系统中,Consistency(一致性). Availability(可用性).Partition tolerance(分区容错性),三者不可兼得 分布式系 ...