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.

解题思路:

就是花最少的钱买最多的东西,需要注意的就是公式axj + xj·k ,xj代表的是所选择的数字的下标,所以要先用公式算出其价格,再进行排序。然后就是超时的问题,可以写个二分。

第一次看到c题比b题简单。。怕不是序号出反了

实现代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,b[],a[],rep,S;
bool check(ll k){
for(int i = ; i < n; i++) b[i] = a[i] + k * (i + );
rep = ;
sort(b, b + n);
for(int i = ; i < k; i++) rep += b[i];
return rep <= S;
} int main(){
ll ans = ;
cin >> n >> S;
for(int i = ; i < n; i++) cin >> a[i];
int l = , r = n;
while(l <= r){
int m = (l + r) / ;
if(check(m)){
l = m + ;
ans = rep;
} else r = m - ; }
cout << (l - ) << " " << ans;
return ;
}

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market的更多相关文章

  1. 【二分】Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market

    傻逼二分 #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll ...

  2. Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister —— DP

    题目链接:http://codeforces.com/problemset/problem/812/B B. Sagheer, the Hausmeister time limit per test ...

  3. Codeforces Round #417 (Div. 2) D. Sagheer and Kindergarten(树中判祖先)

    http://codeforces.com/contest/812/problem/D 题意: 现在有n个孩子,m个玩具,每次输入x y,表示x孩子想要y玩具,如果y玩具没人玩,那么x就可以去玩,如果 ...

  4. Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister

    http://codeforces.com/contest/812/problem/B 题意: 有n层楼,每层楼有m个房间,1表示灯开着,0表示灯关了.最两侧的是楼梯. 现在每从一个房间移动到另一个房 ...

  5. Codeforces Round #417 (Div. 2)-A. Sagheer and Crossroad

    [题意概述] 在一个十字路口 ,给定红绿灯的情况, 按逆时针方向一次给出各个路口的左转,直行,右转,以及行人车道,判断汽车是否有可能撞到行人 [题目分析] 需要在逻辑上清晰,只需要把所有情况列出来即可 ...

  6. 【动态规划】Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister

    预处理每一层最左侧的1的位置,以及最右侧的1的位置. f(i,0)表示第i层,从左侧上来的最小值.f(i,1)表示从右侧上来. 转移方程请看代码. #include<cstdio> #in ...

  7. [Codeforces Round#417 Div.2]

    来自FallDream的博客,未经允许,请勿转载,谢谢. 有毒的一场div2 找了个1300的小号,结果B题题目看错没交  D题题目剧毒 E题差了10秒钟没交上去. 233 ------- A.Sag ...

  8. Codeforces Round #417 (Div. 2)A B C E 模拟 枚举 二分 阶梯博弈

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

  9. Codeforces Round #417 (Div. 2) 花式被虐

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

随机推荐

  1. 自行实现高性能MVC

    wcf虽然功能多.扩展性强但是也面临配置忒多,而且restful的功能相当怪异,并且目前没法移植.asp.net core虽然支持webapi,但是功能也相对繁多.配置复杂.就没有一个能让码农们安安心 ...

  2. Linux安装maven以及配置-Centos7版本

    1.Linux安裝maven 1.如果電腦沒有wget命令的,先使用yum安裝wget命令.eg: yum install wget 2.安裝好后就可以直接使用wget命令去下載maven. 附:打开 ...

  3. sql语句 update

    UPDATE ban_group AS A SET  NAME ='锅炉三班' FROM     hr_employee AS b  WHERE     b.job_no = '1394' AND A ...

  4. Dubbo(四) Dubbo-Admin项目 Dubbo管理台

    前言 在dubbo项目中,有注册中心,消费者,提供者就足以构成一个完整的项目了.但是仅仅有这三个角色,很难对整个项目状态有直观的了解,以及对项目操作. 因此早有前辈对此原因作出了贡献——一个通用的du ...

  5. Js基础---红宝书读书日记(1)-------基本类型和引用类型

    JS的变量可能包含两种不同数据类型的值,基本类型和引用类型; 基本类型是指简单的数据段,引用类型是指可能由多个值构成的对象; JS高级程序设计第三章介绍了变量分为 5种简单数据类型(string/nu ...

  6. linux下文件加密方法总结

    为了安全考虑,通常会对一些重要文件进行加密备份或加密保存,下面对linux下的文件加密方法做一简单总结: 方法一:gzexe加密这种加密方式不是非常保险的方法,但是能够满足一般的加密用途,可以隐蔽脚本 ...

  7. 898 C. Phone Numbers

    传送门 [http://codeforces.com/contest/898/problem/C] 题意 题意比较难理解直接看样例就知道了,给你个n接下来n行,每行包括一个名字和号码的数量,还有具体的 ...

  8. 对我们最常用的软件QQ的看法

    QQ聊天软件是我使用的第一款聊天软件,早在我上小学6年级的时候就开始接触这款软件了,可以说是陪伴我最久的一款软件. 相对于其他的聊天软件,QQ更加的方便,使用简单,界面也好操作,所以我爱上了这款软件. ...

  9. Week 7 迭代总结

    写在前面: 本次我为团队博客写了一篇总结,深刻总结了我们组发生的问题以及将来要做的事情.有兴趣请移步http://www.cnblogs.com/Buaa-software Week 7 Alpha轮 ...

  10. 《Linux内核分析》chapter4