CF812C Sagheer and Nubian Market 二分+贪心

Posted guangheli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF812C Sagheer and Nubian Market 二分+贪心相关的知识,希望对你有一定的参考价值。

模拟赛给他们出T1好了~

code: 

#include <bits/stdc++.h>  
#define ll long long  
#define N 100006 
#define setIO(s) freopen(s".in","r",stdin) 
using namespace std;   
int n; 
ll a[N],ck,A[N],S; 
int check(int tmp) 

    int i,cnt=0;    
    for(i=1;i<=n;++i) A[i]=a[i]+1ll*tmp*i;  
    sort(A+1,A+1+n);                                                                              
    ll pp=0; 
    for(i=1;i<=n;++i) 
     
        if(pp+A[i]>S) break; 
        else
        
            pp+=A[i]; 
            ++cnt; 
            if(cnt==tmp) break; 
        
     
    if(cnt>=tmp) 
    
        ck=pp; 
        return 1; 
    
    return 0; 

int main() 
   
    int i,j; 
    // setIO("input");  
    scanf("%d%lld",&n,&S);              
    for(i=1;i<=n;++i) scanf("%lld",&a[i]);      
    int l=1,r=n,mid,ans=0;   
    for(;l<=r;) 
            
        mid=(l+r)>>1;    
        if(check(mid)) ans=mid,l=mid+1;  
        else r=mid-1;  
    
    printf("%d %lld\n",ans,ck); 
    return 0; 

  

以上是关于CF812C Sagheer and Nubian Market 二分+贪心的主要内容,如果未能解决你的问题,请参考以下文章

codefoces812C-Sagheer and Nubian Market心得

Round #417 C. Sagheer and Nubian Market(Div.2)

#417(div2) C. Sagheer and Nubian Market

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序

#417 Div2 Problem C Sagheer and Nubian Market (二分 && std::accumulate)

Codeforces 812E Sagheer and Apple Tree