codeforces 812 C. Sagheer and Nubian Market(二分答案)
来源:互联网 发布:淘宝裂变有危险吗 编辑:程序博客网 时间:2024/06/05 19:34
题意:
n个商品,有s块钱,买第i件商品的价格为a[i]+i*k,a[i]为商品的基础价格,k为总共要买的商品数量,问最多能买多少件商品,在买相同数量的商品情况下,尽量让花的钱最少。
解题思路:
二分枚举要买的商品数量,然后排序一下价格,check是否能买到当前答案数量的商品,求出一个最大值即可。
代码:
#include <bits/stdc++.h>using namespace std;const int maxn=1e5+5;long long a[maxn];long long b[maxn];int main(){ int n, s, i; long long j; cin>>n>>s; for(i=1; i<=n; i++) { scanf("%lld", &a[i]); } long long l=0, r=n, mid; long long m, ans=0, sum=0; for(i=0; i<50; i++)//枚举次数视题目而定 {// cout<<l<<" "<<r<<endl; mid=(l+r)>>1; m=0; for(j=1; j<=n; j++) { b[j]=a[j]+j*mid; } sort(b+1, b+n+1); for(j=1; j<=mid; j++) { m+=b[j]; if(m>s)break; } if(j<=mid) { r=mid-1; } else { ans=mid; sum=m; l=mid+1; } } printf("%lld %lld\n", ans, sum); return 0;}
阅读全文
0 0
- codeforces 812 C. Sagheer and Nubian Market(二分答案)
- Codeforces 812C Sagheer and Nubian Market[二分]
- Codeforces 812C Sagheer and Nubian Market【二分】水题
- 【Codeforces 812 C. Sagheer and Nubian Market】+ 二分
- codeforces 812C Sagheer and Nubian Market (二分)
- Codeforces 812C-Sagheer and Nubian Market
- Codeforces 812 C Sagheer and Nubian Market
- Codeforces 812C Sagheer and Nubian Market
- codeforces 812C Sagheer and Nubian Market
- CF# 812 C. Sagheer and Nubian Market(二分)
- codeforces 812C——Sagheer and Nubian Market(二分)
- C. Sagheer and Nubian Market
- Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分基础入门裸题
- Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market(二分查找)
- Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market
- Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market
- Sagheer and Nubian Market(二分)
- Sagheer and Nubian Market (二分)
- STM32F1x系列——按键输入实验
- Unable to find a single main class from the following candidates
- 江学院-Problem K: qwb与小数
- java反射的field.get(null)
- php时间获取
- codeforces 812 C. Sagheer and Nubian Market(二分答案)
- opencv sample导入到Android studio(tutorial部分)
- 【C】控制台限时输入控制。。
- toolbar和popupwindow的使用
- pybot参数介绍
- Linux usb gadget configfs用法
- 多进程服务器
- PHP 设计模式---单例模式
- javaWeb服务详解【客户端调用】(含源代码,测试通过,注释) ——测试