557C(codeforce)

本文分享了一次参与CF编程比赛的经历,针对一道题目进行了详细的解析与代码实现。通过对题目的深入理解,作者总结出了最优解策略,并通过具体代码展示了如何实现这一策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近忙着考试,根本没有时间刷题==,突然发现小X在不停的刷CF,默默攒下了,嗯,上场的C真心没有想法,归根结底还是暴力,贴下别人的代码把,我是看他的思路做的,现在多少是明白了。这题归根还是想法,确实是没有想到那里。

#include <bits/stdc++.h>

#define LOCAL
#define ll  long long
#define lll unsigned long long
#define MAX 1000009
#define eps 1e-8
#define INF 0x7fffffff
#define mod 1000000007
#define For(i,n) for(i=0;i<n;i++)

using namespace std;


int  m[MAX];
int sum = 0;
struct node
{
    int l;
    int d;
    bool operator < (const node &b)const
    {
        return l > b.l;
    }
} p[MAX];


int main()
{
    //freopen("data.txt","r",stdin);
    int n,i;
    memset(m,0,sizeof(m));
    scanf("%d",&n);
    for(i  = 0; i<n; i++)scanf("%d",&p[i].l);
    for(i  = 0; i<n; i++)
    {
        scanf("%d",&p[i].d);
        sum+=p[i].d;
        m[p[i].d]++;
    }
    sort(p,p+n);//长度从大到小排序
    /*for(i = 0;i<n;i++)
    {
        cout<<p[i].len<<" "<<p[i].d<<endl;
    }*/
    int res = 0,temp = 0, cnt = 0;
    for(i  = 0; i<=n; i++) //枚举长度,等于n是把最后也算进去
    {
        if(i==0||p[i].l==p[i - 1].l)
        {
            temp+=p[i].d;//当前长度下的总消耗
            m[p[i].d]--;
            cnt++;//这种长度有多少个
        }
        else
        {
            for(int k=200; k>=1; k--) //判断力气,剩下的cnt - 1个是什么都可以,只要保证力气足够大
            {
                if(m[k]>0)
                {
                    if(m[k]<=cnt-1)
                    {
                        temp+=m[k]*k;
                        cnt-=m[k];
                    }
                    else
                    {
                        temp+=(cnt- 1)*k;//直接消耗了num-1个
                        cnt = 1;
                    }
                }
                if(cnt<=1)break;
            }
            res = max(res,temp);
            temp = p[i].d;
            cnt = 1;
            m[p[i].d]--;

        }
    }
    printf("%d\n",sum - res);
    return  0;
}


### Codeforces Problem or Contest 998 Information For the specific details on Codeforces problem or contest numbered 998, direct references were not provided within the available citations. However, based on similar structures observed in other contests such as those described where configurations often include constraints like `n` representing numbers of elements with defined ranges[^1], it can be inferred that contest or problem 998 would follow a comparable format. Typically, each Codeforces contest includes several problems labeled from A to F or beyond depending on the round size. Each problem comes with its own set of rules, input/output formats, and constraint descriptions. For instance, some problems specify conditions involving integer inputs for calculations or logical deductions, while others might involve more complex algorithms or data processing tasks[^3]. To find detailed information regarding contest or problem 998 specifically: - Visit the official Codeforces website. - Navigate through past contests until reaching contest 998. - Review individual problem statements under this contest for precise requirements and examples. Additionally, competitive programming platforms usually provide comprehensive documentation alongside community discussions which serve valuable resources when exploring particular challenges or learning algorithmic solutions[^2]. ```cpp // Example C++ code snippet demonstrating how contestants interact with input/output during competitions #include <iostream> using namespace std; int main() { int n; cin >> n; // Process according to problem statement specifics } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值