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
  1. 3 11
  2. 2 3 5
output
  1. 2 11
input
  1. 4 100
  2. 1 2 5 6
output
  1. 4 54
input
  1. 1 7
  2. 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.

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

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

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

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

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <queue>
  8. #include <stack>
  9. #include <map>
  10. #include <set>
  11. #include <cmath>
  12.  
  13. using namespace std;
  14.  
  15. #define LL long long
  16. const int inf=0x7fffffff;
  17. int n;
  18. LL s;
  19. LL a[100005];
  20. LL b[100005];
  21.  
  22. bool ok(int x)
  23. {
  24. for(int i=0; i<n; i++)
  25. {
  26. b[i]=a[i]+(LL)(i+1)*x;
  27. }
  28. sort(b,b+n);
  29. LL sum=0;
  30. for(int i=0; i<x; i++)
  31. sum+=b[i];
  32. if(sum<=s)
  33. return 1;
  34. return 0;
  35. }
  36.  
  37. int main()
  38. {
  39. while(~scanf("%d%d",&n,&s))
  40. {
  41. for(int i=0; i<n; i++)
  42. scanf("%lld",&a[i]);
  43. int l=1,r=n;
  44. int ans=0;
  45. while(l<=r)
  46. {
  47. int mid=(l+r)>>1;
  48. if(ok(mid)) l=mid+1,ans=mid;
  49. else r=mid-1;
  50. }
  51. for(int i=0; i<n; i++)
  52. {
  53. b[i]=a[i]+(LL)(i+1)*ans;
  54. }
  55. sort(b,b+n);
  56. LL sum=0;
  57. for(int i=0; i<ans; i++)
  58. sum+=b[i];
  59. printf("%d %lld\n",ans,sum);
  60. }
  61.  
  62. return 0;
  63. }

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. 20.Mysql锁机制

    20.锁问题锁是计算机协调多个进程或线程并发访问某一资源的机制. 20.1 Mysql锁概述锁类型分为表级锁.页面锁.行级锁.表级锁:一个线程对表进行DML时会锁住整张表,其它线程只能读该表,如果要写 ...

  2. html与css关系

    1.html是网页的内容的载体 内容是作者发在页面想让用户浏览的信息,包括文字,图片,视频等 2.css样式是表现 像网页的外衣,比如标题字体的变化,颜色的变化,背景颜色,边框等,所有这些都是用来改变 ...

  3. Eclipse中的maven项目搭建

    一.eclipse中的maven设置 1.打开“首选项”----> "maven"---->"Installations".用来查看maven的使用 ...

  4. HDU_2136

    #include <iostream> #include <stdio.h> #include <math.h> #include <algorithm> ...

  5. MacDev.GarbageCollectionIsDeprecated-WhenXcodeCompileMacAppProject

    Garbage Collection is not supported 当Xcode编译Mac OSX App时报错:"Garbage Collection is not supported ...

  6. js 闭包 弊端

    闭包有许多有趣的用途,Javascript的两个特征使它这么有趣:1. function是一个对象,它跟数组,Object一样,地位平等.2. Javascript变量作用域范围.<Javasc ...

  7. java 环境搭建

    一.安装jdk 下载jdk http://www.oracle.com/technetwork/java/javase/downloads 将下载的jdk文件放到 /opt 下解压 $sudo cp ...

  8. Spring Boot REST(二)源码分析

    Spring Boot REST(二)源码分析 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) SpringBoot RE ...

  9. 让UI设计师崩溃的瞬间,你经历过哪些?

    隔行如隔山,这句话人人耳熟能详,但其实隔行并不可怕,大家各谋其事,各尽其职,倒也互不打扰,真正可怕的是,是内行还要受外行指点江山,而最难的部分,便是那沟通.流畅的沟通,和声细语,是有如时雨之化者:无效 ...

  10. windows 下设置nginx负载均衡

    #user nobody; worker_processes ; #error_log logs/error.log; #error_log logs/error.log notice; #error ...