首页 > 代码库 > 812C - Sagheer and Nubian Market
812C - Sagheer and Nubian Market
Sagheer and Nubian Market
二分+排序
比赛时没对,赛后检查才发现check()里的参数类型是int 改成ll就对了。好气哦!
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N = 1e5+10; 5 ll a[N], b[N], k, t, n, l, r, s, ans; 6 7 bool check(ll x ){ 8 for(int i =1; i <=n ; i ++){ 9 b[i] = a[i]+i*x; 10 } 11 sort(b+1,b+n+1); 12 ans=0; 13 for(int i = 1; i <=x; i ++){ 14 ans+=b[i]; 15 } 16 if(ans>s)return false; 17 else return true; 18 } 19 20 int main(){ 21 cin >> n >> s; 22 for(int i = 1; i <= n; i ++)scanf("%lld",&a[i]); 23 l = 1, r = n; 24 while(l<=r){ 25 ll mid = (l+r)/2; 26 if(check(mid)){ 27 k = mid; 28 t = ans; 29 l = mid+1; 30 }else{ 31 r = mid-1; 32 } 33 } 34 cout << k << " " << t << endl; 35 return 0; 36 }
812C - Sagheer and Nubian Market
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。