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
  1. 3 11
    2 3 5
output
  1. 2 11
input
  1. 4 100
    1 2 5 6
output
  1. 4 54
input
  1. 1 7
    7
output
  1. 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题简单。。怕不是序号出反了

实现代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. ll n,b[],a[],rep,S;
  5. bool check(ll k){
  6. for(int i = ; i < n; i++) b[i] = a[i] + k * (i + );
  7. rep = ;
  8. sort(b, b + n);
  9. for(int i = ; i < k; i++) rep += b[i];
  10. return rep <= S;
  11. }
  12.  
  13. int main(){
  14. ll ans = ;
  15. cin >> n >> S;
  16. for(int i = ; i < n; i++) cin >> a[i];
  17. int l = , r = n;
  18. while(l <= r){
  19. int m = (l + r) / ;
  20. if(check(m)){
  21. l = m + ;
  22. ans = rep;
  23. } else r = m - ;
  24.  
  25. }
  26. cout << (l - ) << " " << ans;
  27. return ;
  28. }

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. 介绍一个axios调试好用的工具:axios-mock-adapter

    上一篇文章中写到用promise时应注意的问题,这一篇文章继续介绍一个可以和axios库配合的好工具: axios-mock-adapter.axios-mock-adapter可以用来拦截http请 ...

  2. React-引入图片的方法

    方法一: import imgURL from '../../images/logo.png'; <img src={imgURL} alt="1"/> 方法二: &l ...

  3. asp.net web api集成微信服务(使用Senparc微信SDK)- z

    /// <summary> /// 微信请求转发控制器 /// </summary> [RoutePrefix("weixin")] public clas ...

  4. IOC框架之 Unity 入门

    十年河东,十年河西,莫欺少年穷 学无止境,精益求精 Unity是什么? Unity是patterns & practices团队开发的一个轻量级.可扩展的依赖注入容器,具有如下的特性: 1. ...

  5. MiniProfiler工具介绍(监控EF生成的SQL语句)--EF,迷你监控器,哈哈哈

    十年河东,十年河西,莫欺少年穷... 今天是抄袭的别人的博客,不过我感觉蛮好,挺有用,特别是老板让你优化EF项目SQL耗时的情况下,你可以采用这种方式来优化你的LINQ. 时间很宝贵,废话还是不多说, ...

  6. iOS app签名原理

    基本原理: 公钥能够验证私钥的签名是否正确. Apple后台有一个私钥A,iOS内置一个公钥A,与私钥A对应.(A:代表Apple,即苹果) 本地产生一对公钥L.私钥L,(L:代表Local,即本地) ...

  7. C语言基础复习:字符,字符数组,字符串,字符指针

    1. 概述2. 字符2.1 字符定义和大小2.2 字符的输入和输出2.3 字符的计算3. 字符数组3.1 字符数组的定义和大小3.2 字符数组的输入和输出3.3 字符数组的计算4. 字符串4.1 字符 ...

  8. vs2017+opencv4.0.1安装配置详解(win10)

    一.说明 笔者之前已经安装过了vs2017,对应的opencv是3.4.0版本的.但现在想体验下opencv4的改变之处,所以下载了最新的opencv4.0.1. vs2017的安装请自行搜索安装,本 ...

  9. 印象深刻的bug

    测试中测到一个印象比较深刻的bug,问题出现在web端的电商平台,展示商品的时候每点击一个商品相应的url=~/productid.html,如果知道productid可以直接在url输入跳转到商品详 ...

  10. 牛客网-小白月赛6-J-洋灰三角

    题目链接https://www.nowcoder.com/acm/contest/136/J 这题我还是不找规律了,老老实实推吧,传说找规律也可以,我还是算了 递推式:f(n)=k*f(n-1)+p ...