CodeForces 614D Skills

排序+枚举+二分

最大的那些变成A,小的那部分提高最小值

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int maxn=100000+10;
int n;
long long A,cf,cm,m;
struct X
{
    long long a;
    long long ans;
    int id;
} s[maxn];
long long sum[maxn];

bool cmp1(const X&a,const X&b)
{
    return a.a<b.a;
}

bool cmp2(const X&a,const X&b)
{
    return a.id<b.id;
}

int main()
{
    scanf("%d%lld%lld%lld%lld",&n,&A,&cf,&cm,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&s[i].a);
        s[i].id=i;
        s[i].ans=s[i].a;
    }
    sort(s+1,s+1+n,cmp1);
    memset(sum,0,sizeof sum);
    for(int i=1; i<=n; i++) sum[i]=sum[i-1]+s[i].a;
    int ansPos1=0,ansPos2=0;
    long long Max=-1;
    long long ave=0;
    for(int i=0; i<=n; i++) //最后i个都变成A
    {
        long long cost=A*i-(sum[n]-sum[n-i]);//最后i个都变成A需要的费用
        if(cost>m) break;// 如果费用超过了m,则结束

        cost=m-cost;//剩余的费用
        int left=1,right=n-i;//二分查找的范围
        int pos=0;
        while(left<=right)
        {
            int mid=(left+right)/2;
            if(mid*s[mid].a-sum[mid]<=cost)
            {
                pos=mid;
                left=mid+1;
            }
            else right=mid-1;
        }
        long long q;
        if(pos!=0) q=min(A,(cost-pos*s[pos].a+sum[pos])/pos+s[pos].a);
        else q=A;
        if(q*cm+i*cf>Max)
        {
            Max=q*cm+i*cf;
            ansPos1=pos;
            ansPos2=i;
            ave=q;
        }
    }

    for(int i=n;i>=n-ansPos2+1;i--) s[i].ans=A;
    for(int i=1;i<=ansPos1;i++) s[i].ans=ave;

    printf("%lld\n",Max);
    sort(s+1,s+n+1,cmp2);
    for(int i=1;i<=n;i++)
    {
        printf("%lld",s[i].ans);
        if(i<n) printf(" ");
        else printf("\n");
    }
    return 0;
}
时间: 2024-11-11 06:03:15

CodeForces 614D Skills的相关文章

[CodeForces - 614D] D - Skills

D - Skills Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai

Codeforces 614D 二分

D. Skills 题意: 给出 n, A, cf, cm, m,表示有 n 个技能,每个技能当前水平为 a[i] ,最高水平为 A ,有 m 个技能点,花费一个技能点可以使任意一个技能水平加一 (最高只能是 A). 如果最后水平为 A 的技能有 x 个,最低的技能水平值为 y,定义权值为 cf*x+cm*y .求可能的最高权值,并输出最后每个技能的水平. tags: 枚举 x ,对当前 x 二分可能的最低水平值,check 时还要再二分一下. // 614D #include<bits/std

「日常训练」Skills(Codeforce Round Div.2 #339 D)

题意(CodeForces 614D) 每个人有\(n(n\le 10^5)\)个技能,技能等级都在\([0,10^9]\)的范围,每个技能有一个当前等级,所有技能的最高等级都为A.一个人的力量被记做以下两项的和: 1. 顶级技能的个数 *cf 2. 最低等级的技能 *cm 每个单位的钱能够提升一级力量.我们希望花尽可能少的钱,使得力量尽可能高. 分析 我二分的功力还是不足,要多努力.这题其实是一个非常明显的暴力:我们枚举提高到A的等级的个数(到不能提升为止),枚举这种情况下,我们能够令把多少人

Codeforces 581C Developing Skills

C. Developing Skills Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number 

CodeForces 42A Guilty — to the kitchen!

Guilty — to the kitchen! Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 42A Description It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore force

Codeforces Round #277.5 (Div. 2) JAVA版题解

Codeforces Round #277.5 (Div. 2) A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In this problem your goal is to sort an array consisting of n integers in at most n swaps. For t

codeforces 489B. BerSU Ball 解题报告

题目链接:http://codeforces.com/problemset/problem/489/B 题目意思:给出 n 个 boys 的 skills 和 m 个 girls 的 skills,要求成 pair 的条件为,男和女的 skill 差值最多只能为 1.问成 pair 最多是多少. 这个不太难,关键是要考虑周全. 对于某个人,假设他(男)的 skill 值为 i,那么跟他成 pair 的人的 skill 值,只有三种:i-1,i,i+1.跟他成对的女要减少一个.然后女的那边也要搜一

Educational Codeforces Round 55 (Rated for Div. 2) C. Multi-Subject Competition 【vector 预处理优化】

传送门:http://codeforces.com/contest/1082/problem/C C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A multi-subject competition is coming! The competition has mm 

Codeforces Round #587 (Div. 3) B - Shooting

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564214.html Codeforces Round #587 (Div. 3) B - Shooting Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a ta