Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market
来源:互联网 发布:mac number 编辑:程序博客网 时间:2024/06/06 02:03
传送门
题意:有S的预支。n个商品。问能买几件商品。输出能买几件商品,并输出最少花费的钱。 花费的钱除了商品的价格还要加上x(代表能买几件商品)*i(下标)
#include <bits/stdc++.h>//#include <ext/pb_ds/tree_policy.hpp>//#include <ext/pb_ds/assoc_container.hpp>//using namespace __gnu_pbds;using namespace std;#define pi acos(-1)#define endl '\n'#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0);#define rand() srand(time(0));typedef long long LL;typedef pair<int, int> pii;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,1,0,0,-1,-1,1,1};const int dy[]={0,0,1,-1,1,-1,1,-1};const int maxn=1e3+5;const int maxx=1e5+100;const double EPS=1e-9;const int MOD=1000000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;/*lch[root] = build(L1,p-1,L2+1,L2+cnt); rch[root] = build(p+1,R1,L2+cnt+1,R2);中前*//*lch[root] = build(L1,p-1,L2,L2+cnt-1); rch[root] = build(p+1,R1,L2+cnt,R2-1);中后*/long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}inline int Scan(){ int res=0,ch,flag=0; if((ch=getchar())=='-')flag=1; else if(ch>='0' && ch<='9')res=ch-'0'; while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0'; return flag ? -res : res;}LL n,s;LL a[maxx],b[maxx],cnt,sum;int check(int x){ cnt=0; for(int i=1;i<=n;i++) b[i]=a[i]+1LL*x*i;//每次处理一下b数组 sort(b+1,b+n+1);//排序 for(int i=1;i<=x;i++) cnt+=b[i];//取前面x个 //cout<<cnt<<endl; if(cnt<=s) return 1; else return 0;}int main(){ cin>>n>>s; for(int i=1;i<=n;i++) cin>>a[i]; int l=0,r=n; while(l<=r)//二分能买的商品个数 { int mid=(l+r)>>1; if(check(mid)) { l=mid+1; sum=cnt; } else r=mid-1; } cout<<(l-1)<<" "<<sum<<endl;}
阅读全文
0 0
- 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(二分查找)
- Codeforces Round #417 (Div. 2)Sagheer, the Hausmeister 乱搞 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
- 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 812 C. Sagheer and Nubian Market】+ 二分
- codeforces 812C Sagheer and Nubian Market (二分)
- Sagheer and Nubian Market
- Sagheer and Nubian Market
- Sagheer and Nubian Market
- java web介绍及今天所学
- 实现鼠标点击及键盘控制下拉菜单事件
- getClientRects 和 getBoundingClientRect 的用法和区别
- 码率、延时、花屏、卡顿
- HTTP用不了,修改info.plist文件
- Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market
- VC注册表写入和读取字符串
- bootstarp-按钮
- Luncene学习笔记 -- day03 入门程序
- 在springboot项目中引入swagger2时出现Circular view path [swagger-ui]
- Android手机系统数据连接核心类-java层说明
- Is it possible to implement IPv6 on a virtual interface (eth0:1 interface) in Linux?
- win7系统开机出现OEM7GRUB 0.4.4提示无法进入系统的原因及两种解决方法
- JDK同步控制工具,JAVA高并发程序设计