time limit per test  2 seconds
memory limit per test  256 megabytes
 

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 buysk 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 ksouvenirs.

 
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 [, , ] with total cost . If he decides to take only two items, then the costs will be [, , ]. So he can afford the first and second items. In the second example, he can buy all items as they will cost him [, , , ]. In the third example, there is only one souvenir in the market which will cost him pounds, so he cannot buy it.

Note


题目大意:
     在一个商店里一共有n件商品,每一件都有一个基础价格,但是这个商店有一个奇怪的规定,
     每一件商品最后的价格为 基础价格+买的商品总件数*商品的坐标(即这是第几件商品)
     现给定 商品的件数和你所拥有的钱数, 问你最多能卖几件商品 花的总钱数是多少 解题思路:
     总体思路为:二分查找 先找出最多能买的商品的件数,然后在计算出总花费 AC代码:
 #include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; int main ()
{
ll n,s,sum,x,y,l,r;
ll ans[],a[];
int i;
cin>>n>>s;
for (i = ; i <= n; i ++)
cin>>a[i]; l = ,r = n; // 左标签和右标签
x = y = ;
while (l <= r){
sum = ;
ll mid = (r+l)>>; // 二分枚举能购买的商品件数
for (i = ; i <= n; i ++)
ans[i] = a[i]+i*mid;
sort(ans+,ans++n);
for (i = ; i <= mid; i ++)
sum += ans[i];
if (sum <= s){
x = mid;
y = sum;
l = mid+;
}
else
r = mid-;
}
cout<<x<<" "<<y<<endl;
return ;
}
以下版本思路同上;
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int main ()
{
__int64 n,s;
__int64 ans[],a[];
int i;
while (~scanf("%I64d%I64d",&n,&s))
{
for (i = ; i <= n; i ++)
scanf("%I64d",&a[i]); int l = ,r = n;
__int64 sum,x=,y=;
while (l <= r){
sum = ;
long long mid = (l+r)>>;
for (i = ; i <= n; i ++)
ans[i] = a[i]+i*mid;
sort(ans+,ans++n);
for (i = ; i <= mid; i ++)
sum += ans[i];
if (sum > s)
r = mid-;
else
l = mid+;
}
for (i = ; i <= n; i ++)
ans[i] = a[i]+i*r;
sort(ans+,ans++n);
for (i = ; i <= r; i ++)
y += ans[i];
printf("%d %I64d\n",r,y);
}
return ;
}

 

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

  1. Codeforces Round #417 B. Sagheer, the Hausmeister

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

  2. AC日记——Sagheer and Nubian Market codeforces 812c

    C - Sagheer and Nubian Market 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #defin ...

  3. Codeforces J. Sagheer and Nubian Market(二分枚举)

    题目描述: Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes in ...

  4. CodeForce-812C Sagheer and Nubian Market(二分)

    Sagheer and Nubian Market CodeForces - 812C 题意:n个货物,每个货物基础价格是ai. 当你一共购买k个货物时,每个货物的价格为a[i]+k*i. 每个货物只 ...

  5. [Codeforces Round#417 Div.2]

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

  6. Codeforces812C Sagheer and Nubian Market 2017-06-02 20:39 153人阅读 评论(0) 收藏

    C. Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. 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 ...

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

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

  9. codeforces round 417 div2 补题 CF 812 A-E

    A Sagheer and Crossroads 水题略过(然而被Hack了 以后要更加谨慎) #include<bits/stdc++.h> using namespace std; i ...

随机推荐

  1. 参数化测试与Mock

    参数化测试与Mock 转载自https://blog.csdn.net/sunliduan/article/details/42026509 单元测试概念 说到测试,大家都不会陌生,从我们开始学习编程 ...

  2. Mac 10.12安装Command+Q误按提示工具

    说明:很多时候不小心会按强制关闭而无任何提示,这款工具能延迟关闭,并有相应的提示. 下载: (链接: https://pan.baidu.com/s/1bpyJMPL 密码: bqn1)

  3. 高性能的数据压缩库libzling-20160105

    libzling(https://github.com/richox/libzling,求观看[watch],求星[star],求叉[fork])是一款高性能的数据压缩库,参见原贴:http://ww ...

  4. jquery mobile 动态加载标签时,无法正常展示样式

    原因 在chrome中审查元素,发现其增加了很多没有直接写在页面上的标签和样式.页面标签首先经过jquery.mobile-1.4.5.min.js的处理,添加了许多标签,然后再用css布局 解决方案 ...

  5. Http协议之Content-Length

    前言 http协议是互联网中最重要的协议之一,虽然看上去很简单,但是实际中经常遇到问题,我们就已经遇到好几次了.有长连接相关的,有报文解析相关的.对http协议不能一知半解,必须透彻理解才行.所以就写 ...

  6. Datenstruktur und Algorithmus

    In der Informatik und Softwaretechnik ist eine Datenstruktur ein Objekt zur Speicherung und Organisa ...

  7. python之virtualenv的简单使用

    什么是virtualenv? virtualenv可以创建独立Python开发环境,比如当前的全局开发环境是python3.6,现在我们有一个项目需要使用django1.3,另一个项目需要使用djan ...

  8. 玩转树莓派《三》——Scratch

    今天大姨妈折磨了一整个白天,稍微好点,现在打开实验楼,看到有个朋友回答了关于ubuntu上面操作SQL 的时候到处数据到txt文件,被批评没有思考问题,或许吧,虽然那个权限我现在想起确实是可读可写的, ...

  9. A记录,CNAME,MX记录,TTL

    A记录 A记录是用来指定主机名(或域名)对应的IP地址记录.用户可以将该域名下的网站服务器指向到自己的web server上.同时也可以设置您域名的二级域名. MX记录 MX记录邮件路由记录,用户可以 ...

  10. DataGridView 绑定数据方法

    DataGridView控件用于显示来自多种外部数据源中的数据,用户可以在此控件添加行和列,并可以填充数据.   如要让DataGridView显示数据库中的数据,只需要将此控件绑定到挑用数据库的数据 ...