CodeForces
来源:互联网 发布:斗鱼抢票软件多少钱 编辑:程序博客网 时间:2024/05/16 10:47
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 k, T — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs.
Example
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.
这个题二分就可以…
每次合理取小的
我也不知道为啥要longlong反正不对就longlong交一发
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;#define int long longint tu[100001],ss[100001];int n, s;int jiance(int k){ int fs = 0; for (int a = 1; a <= n; a++) { ss[a] = tu[a] + k*a; } sort(ss + 1, ss + n + 1); for (int a = 1; a <= k; a++) { fs += ss[a]; } if (fs > s)return 0; return fs;}main(){ cin >> n >> s; for (int a = 1; a <= n; a++)scanf("%I64d", &tu[a]); int z = 1, y = n; int daan1 = 0,daan2=0x3f3f3f3f; while (z <= y) { int mid = (z + y) / 2; int tt = jiance(mid); if (tt) { if (daan1 == mid) { daan2 = min(daan2, tt); } else if (daan1 < mid) { daan1 = mid; daan2 = tt; } z = mid + 1; } else y = mid - 1; } if (daan1 == 0)daan2 = 0; cout << daan1 << " " << daan2;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 常用ntp服务器地址
- 微信小程序:商城系列专辑(开发指南+精品Demo)
- Javaweb学习笔记---Servlet相关类
- UI
- String StringBuffer StringBuilder类
- CodeForces
- Java---查找数据库的smt_lampcontroller表中,行号为奇数的所有数据的id号,报错以及解决办法
- Android 面试题汇总
- 如何发布自己的开源框架到 CocoaPods
- 简单学生选课系统之功能描述和分析
- 20岁不考证,25岁不加班,30岁不熬夜,40岁你还有工作吗?
- oracle中更新字符型数据中的纯数字为定长(不足左边补0)
- linux jar命令不好用
- js中字符串和数组的常用操作