首页 > 代码库 > 【模拟赛】鱼塘钓鱼

【模拟赛】鱼塘钓鱼

简单贪心

# include<cstdio># include<cstring># include<algorithm>using namespace std;const int maxn=10000000+10;int n,k,t;unsigned long long tot;int num[maxn];int main(){    freopen("fishing.in","r",stdin);    freopen("fishing.out","w",stdout);    int x,max=-0x7fffffff;    scanf("%d%d%d",&n,&k,&t);    for(int i=1;i<=n;i++){        scanf("%d",&x);        num[x]++;        if(x>max)max=x;    }    //for(int i=1;i<=4;i++)printf("%d ",num[i]);    for(int i=1;i<=t;i++){        if(max>=k){            tot+=k;            num[max]--;                num[max-k]++;        }        else if(max<k) {            tot+=max;            num[max]--;            num[0]++;        }        for(int j=max;j>=0;j--)        if(num[j]){max=j;break;}        if(max==0)break;    }    printf("%I64u",tot);    return 0;}
View Code

 

【模拟赛】鱼塘钓鱼