当前位置:网站首页>(2022 Niu Ke Duo School 5) B-Watches (two points)

(2022 Niu Ke Duo School 5) B-Watches (two points)

2022-08-02 07:53:00 AC__dream

Title:

Sample input:

4 53 4 5 6

Sample output:

1

The meaning of the question: Given the price of n items, if you buy the k-th item, then the cost of purchasing the i-th item is ai+k*i, ask how many items m yuan can buy at most (the ith itemis the ith in the original sequence)

Analysis: One thing we can easily find is that The answer is monotonic, if I can buy k items, then I mustCan buy k-1 items, this is obvious, so we can sort the items, for every two-point k we need according to ai+k*i is sorted from small to large, and then you can greedily select from front to back to see how many items can be bought with m yuan at most, if it is greater than k, return true, otherwise return false.

Here is the code:

#include#include#include#include#include#include#include#includeusing namespace std;const int N=1e5+10;struct node{int id,v;}p[N];int mid,n,m;bool cmp(node ​​a,node b){return a.v+a.id*mid>n>>m;for(int i=1;i<=n;i++)scanf("%d",&p[i].v),p[i].id=i;int l=0,r=n;while(l>1;if(check(mid)) l=mid;else r=mid-1;}printf("%d",l);return 0;}

原网站

版权声明
本文为[AC__dream]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/214/202208020645449266.html