Codeforces 557C Arthur and Table【思维】

linkfqy#CSDN_blog_backup#【贪心+线段树】Codeforces 557C Arthur and Tabl 暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l 立即下载

C. Arthur and Table
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.

In total the table Arthur bought has n legs, the length of the i-th leg is li.

Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number di — the amount of energy that he spends to remove the i-th leg.

A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.

Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.

Input

The first line of the input contains integer n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought.

The second line of the input contains a sequence of n integers li (1 ≤ li ≤ 105), where li is equal to the length of the i-th leg of the table.

The third line of the input contains a sequence of n integers di (1 ≤ di ≤ 200), where di is the number of energy units that Arthur spends on removing the i-th leg off the table.

Output

Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.

Examples
Input
2
1 5
3 2
Output
2
Input
3
2 4 4
1 1 1
Output
0
Input
6
2 2 1 1 3 3
4 3 5 5 2 1
Output
8

题目大意:

一个桌子有N条腿,每条腿的长度为li,去掉第i个腿用di花费。

一个桌子平稳的规定为:最长长度的腿的数量为num.总腿数为tot.需要满足num>tot/2.


思路:


我们首先按照腿长从小到大排序。

那么我们可以O(n)枚举留下来的桌腿最长的长度是多少。

那么对应假设我们当前枚举留下来的桌腿最长的长度是maxn.那么很明显,大于maxn长度的所有桌腿都要去掉。

那么我们这里可以维护一个前缀和sum【i】表示【1,i】长度区间内所有桌腿去掉的花费.

对应我们枚举留下来的桌腿最长的长度是maxn.其桌腿个数为x个,那么我们可以保留下来小于他长度的桌腿数量为x-1个.

那么我们需要维护小于这个maxn长度的最大价值的x-1个进行保留,其余进行删除。

此时观察到1<=di<=200,那么我们之前可以过程维护每个价值的桌腿都有多少个,那么我们可以从200向1枚举出来x-1个桌腿进行保留,其余的进行删除.

总时间复杂度O(200*n);


Ac代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
    int len,val;
}a[100500];
int sum[100500];
int num[100500];
int have[250];
int cmp(node a,node b)
{
    return a.len<b.len;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(num,0,sizeof(num));
        memset(sum,0,sizeof(sum));
        memset(have,0,sizeof(have));
        for(int i=0;i<n;i++)scanf("%d",&a[i].len),num[a[i].len]++;
        for(int i=0;i<n;i++)scanf("%d",&a[i].val),sum[a[i].len]+=a[i].val;
        sort(a,a+n,cmp);
        for(int i=1;i<=100400;i++)sum[i]=sum[i-1]+sum[i];
        int output=0x3f3f3f3f;
        for(int i=0;i<n;i++)
        {
            int can_live=num[a[i].len]-1;
            int tmp=sum[100400]-sum[a[i].len];
            //printf("--%d %d %d\n",i,tmp,can_live);
            for(int j=200;j>=1;j--)
            {
                if(have[j]>0)
                {
                    if(can_live>=have[j])
                    {
                        can_live-=have[j];
                    }
                    else
                    {
                        tmp+=j*(have[j]-can_live);
                        can_live=0;
                    }
                }
            }
            //printf("--%d %d\n",i,tmp);
            output=min(output,tmp);
            have[a[i].val]++;
        }
        printf("%d\n",output);
    }
}












Python与PyCharm安装配置教程:从零搭建开发环境 编程入门的第一步是搭建开发环境,而Python解释器与IDE工具的选择常让新手困惑。Python作为解释型语言,负责将代码翻译为机器指令,而PyCharm作为集成开发环境,提供代码编辑、调试与项目管理功能,两者协同工作构成高效开发基础。环境变量PATH的配置是安装过程中的关键环节,正确处理可避免“python不是内部或外部命令”的常见错误。理解pip包管理机制,则能轻松安装第三方库并管理项目依赖。从下载官方安装包到运行第一个Hello World程序,再到利用虚拟环境隔离应用依赖,这套流程适用于Window 阅读详情

相关推荐

Educoder | 计算机网络实验-IP协议分析

本关任务:使用 Ping 命令发送数据报,用 Wireshark 截获数据报,分析 IP 数据报的格式,理解 IPV4 地址的编址方法,加深对 IP 协议的理解。

Mksg_28的博客 4809

codeforces 311(div2)C-Arthur and Table

Arthur and Table Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the lengt

lljjccsskk的专栏 551

qt下使用grpc编程(2) —— 练手!自己改的一个简单小例子!1

(1)在研究了grpc官方提供的helloworld例程后,自己试着写了个小程序。 (2)编写proto文件。 proto文件用于定义服务和消息,用protobuf的语法编写,protobuf是一种通信协议,详细请百度。下面附上源码: syntax = "proto3"; option java_multiple_files = true; option java_pac

u011099079的博客 3933

【codeforces 557C Arthur and Table】+ 思维

C. Arthur and Table time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputArthur has bought a beautiful big table into his new flat. When h

楚江枫 747

pix4d安装步骤

pix4d三维模型软件的安装步骤

Little_Bee_27000的博客 1万+

避坑指南:Livox Mid-360双雷达SLAM配置中,那些官方文档没说的细节(IP设置、话题分离与时间同步)

本文详细解析了Livox Mid-360双雷达SLAM配置中的关键优化点,包括IP设置、话题分离与时间同步等官方文档未提及的细节。通过实战案例和代码示例,帮助开发者解决点云错位、IMU数据混乱等问题,提升SLAM系统的稳定性和精度。特别针对网络架构设计、驱动修改和时间同步机制提供了专业指导。

weixin_29745609的博客 430

CF 557C(Arthur and Table-直接暴力)

C. Arthur and Table time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Arthur has bought a beautiful big table

nike0good |Oier&ACMer | 熟能生巧 3540

基于Arduino与脑电模块的意念控制LED灯环实现

脑机接口(BCI)技术通过采集和处理脑电信号,实现人脑与外部设备的直接交互。其核心原理是利用传感器捕捉大脑活动产生的微弱电信号,经过放大、滤波和特征提取,转换为可识别的指令。这项技术在医疗康复、神经反馈训练和人机交互等领域具有重要价值。本文聚焦于一个具体的工程实践:使用消费级NeuroSky TGAM模块采集专注度与放松度数据,通过Arduino平台解析信号,并驱动WS2812B LED灯环实现实时可视化反馈。项目涵盖了硬件选型、电路搭建、数据解析和光效映射等关键环节,为脑机接口入门和嵌入式开发提供了完整的

weixin_28721917的博客 291

Problem - 557C - Codeforces - Arthur and Table

Arthur and TableArthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.In total the table Arthur bought has n legs, the length of th

xiyue_jiang的博客 444

AUTOSAR BswM配置实战:手把手教你用Vector Davinci Configurator搭建第一个模式管理规则

本文详细介绍了如何使用Vector Davinci Configurator工具配置AUTOSAR BswM模块,实现车身控制ECU的模式管理规则。通过实战案例,从环境准备、核心概念梳理到具体配置步骤,包括ModeRequestPort、ModeCondition、Logical Expression和Rules的构建,帮助工程师快速掌握BswM配置技巧,提升汽车电子软件开发效率。

weixin_28678831的博客 358

【agent实战教程】OpenClaw多个agent一文通

一个合格的独立agent,必须具备6个完全独立的专属组件独立组件路径规则核心要求不独立的严重后果唯一agentId配置文件中全局唯一,不能重复,建议用英文+数字,不要有特殊字符agent配置冲突,消息派单错误,会话串线独立工作区(workspace)建议每个agent一个独立文件夹,不要共用人设、记忆、规则混在一起,agent人设崩塌,对话串线独立状态目录(agentDir)固定系统自动生成,绝对禁止多个agent复用同一个agentDir。

海兰 662

Arthur and Table 【CodeForces - 557C】【Splay】

题目链接 有一张桌子,有n个腿。第i根腿的长度是li。 现在要拿掉一些腿,使得桌子稳定,拿掉第i根腿需要di的能量。 稳定的条件是,假如拿掉若干条腿之后,桌子还有k个腿,那么长度最长的腿的数目要超过一半。比如桌子有5根腿,那么至少要有三根腿是最长的。另外,只有一根腿的桌子是稳定的,两个腿的桌子想要稳定,必需长度是一样的。 你的任务是拿掉若干腿,使得桌子稳定,并且所消耗的能量要最少。 ...

既然弱小,就只顾变强就是了 278

信号完整性之串扰

1.前言 串扰(Crosstalk)是指信号线之间由互感、互容而引起的耦合,由于这种耦合的存在,当某一信号线发生电平翻转时,在附近的信号线上将感应到一定程度的噪声。 2. 电路设计中抑制串扰的方法 2.1 控制高速信号线之间的间距和平行走线的长度 多个高速信号长距离平行走线时,其间距应遵循3W原则,如下图所示: 3W原则指两相邻信号线的中心间距不少于信号线宽度的3倍,当满足3W原则时,信号线之间...

sinat_15677011的博客 1万+

CodeForces - 557C. Arthur and Table

C. Arthur and Table time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Arthur has bought a beautiful big table into his new flat. When he came

WwyY9的博客 531

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

codeforce 557C Arthur and Table (思维)

原题地址:http://codeforces.com/problemset/problem/557/C 题意: 一个桌子有n个桌腿,每个桌腿长l,砍断需要体力d,欲使桌子保持平衡,需要砍断部分桌腿,使得剩余的桌腿中长度最大的那些桌腿的数量大于剩余桌腿数量的一半 求使桌子保持平衡最少需要花费的体力 题解: 以某长度Li的桌腿作为最长桌腿,那么大于Li的桌腿全部砍去,小于的部分则...

weixin_30609287的博客 138

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces Round #311 (Div. 2) C. Arthur and Table

C. Arthur and Table time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Arthur has bought a beautiful big table into his n

一点也不二 1708

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

QDU_CEF(补)

C - Arthur and Table Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought hasnlegs, the ...

black_hole6的博客 463

蘑菇街笔试题1

题目一  搬圆桌 现在有一张半径为r的圆桌,其中心位于(x,y),现在他想把圆桌的中心移到(x1,y1)。每次移动一步,都必须在圆桌边缘固定一个点然后将圆桌绕这个点旋转。问最少需要移动几步。 输入描述: 一行五个整数r,x,y,x1,y1(1≤r≤100000,-100000≤x,y,x1,y1≤100000) 输出描述: 输出一个整数,表示答案 输入例子:

走在不归路上 681

Codeforces 557C Arthur and Table 【树状数组 + 二分】

题目链接:Codeforces 557C Arthur and Table C. Arthur and Table time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Arthur has bought a beautiful b

世界很大 802

CodeForces 557C

我智商太低,考试没磨出来。。。 看到200想到桶排,然后先按长度排序,一个一个添加,用一些前缀和数组,就可以直接求出比当前枚举的长度大的总消耗能量值,然后预处理当前长度有多少个,然后再到比这个长度小得里面去找。注意长度相同时要跳过,只枚举一次,不然可能删除之前一个相同长度的桌脚,然而网上很多题解代码没这个处理也过了,cf竟然数据弱,没人hack吗?   =_= #include #includ

binarycopycode 444

CodeForces - 557CArthur and Table(贪心+桶排或权值线段树)

C. Arthur and Tabletime limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Arthur has bought a beautiful big table into his new flat. When he came h

DrWells的博客 507

Codeforces 557C Arthur and Table 砍桌腿

题意:有n个桌腿,要砍掉某些桌腿使得剩下的桌腿能支撑桌子。规定剩下的桌腿中长度最大的桌腿的数量如果超过一半即可支撑桌子。砍掉每个桌腿需要付出代价。求最小的代价和。 枚举。假如最后剩下的桌腿的最大长度为lenth,这样长度的桌腿有num个。那么长度大于lenth的桌腿肯定都被砍去了,然后在剩下的桌腿中按照代价从大到小选择num - 1个桌腿留

FirstLucker 2134

codeforces 557c Arthur and Table

题目链接:http://codeforces.com/problemset/problem/557/C 题目大意:       给出一个桌子,有n个腿,每个腿的长度是l,拆掉这条腿的花费是d,当最长的腿占腿总数大于其他腿的总数,那么合法,问如何才能花费最小到达合法情况 题目分析:       想到枚举最后的最长的那条腿的方法,比这条腿长的腿一定是要拆掉的,所以可以预处理出比长度为i的腿拆掉

weishengmingerfendou的专栏 665

CodeForces - 557C Arthur and Table 预处理 前缀

题目链接:点击查看 题意:有n个桌腿,要砍掉某些桌腿,使剩下的桌腿中长度最大的桌腿的数量如果超过一半。砍掉每个桌腿需要付出代价。求最小的代价和,操蛋,砍掉的意思是直接去掉,我理解成了,可以砍去一部分使其变短,并且长度最长的超过一半没注意到,改了半天被别人提醒才知道,渣渣啊 题解:因为价值最多才200,长度100000,我们可以枚举每个长度,首先长度超过的肯定要去掉,如果还需要去掉再从价值小的去...

还我笑颜 299

codeforces 557 C

因为期末,很久没刷题了,CF一直掉…… 这个题其实很简单。。因为做法很容易想到嘛。。 就是枚举max=x时,最大能保留多少价值,不断更新ans, 结果就是所有价值和减去ans就好 由于最大能够保留的长度是199+200,所以当max=x时,算最大能保留多少价值, 也是一个循环算出当前长度比x小的那个桌子角的最大的那几个价值之和保留就行了, 这里写的比较绕。。反正看看代码一下

Last Order 1192

【贪心+线段树】Codeforces 557C Arthur and Table

题面在这里其实很简单……暴枚最长桌脚的长度ll,然后长度比ll长的桌脚全部都要砍掉长度比ll短的桌脚选择代价前kk小的砍掉用线段树维护……示例程序 :

linkfqy 1005
上一篇: Codeforces 557B Pasha and Tea【二分+思维】
下一篇: Codeforces 557D Vitaly and Cycle【二分图染色+思维】好题~
mengxiang000000
博客等级 码龄11年 627粉丝 2116原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值