博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 557 C
阅读量:7287 次
发布时间:2019-06-30

本文共 2627 字,大约阅读时间需要 8 分钟。

由于期末。非常久没刷题了,CF一直掉……

这个题事实上非常简单。

。由于做法非常easy想到嘛。。

就是枚举max=x时,最大能保留多少价值。不断更新ans,

结果就是全部价值和减去ans就好

因为最大可以保留的长度是199+200,所以当max=x时。算最大能保留多少价值,

也是一个循环算出当前长度比x小的那个桌子角的最大的那几个价值之和保留即可了,

这里写的比較绕。。反正看看代码一下就懂了。。。

维护一个map即可了

比赛的时候,由于好久没刷题了。一直没想清楚,一直到比赛结束前还剩下十分钟才恍然大悟。

复杂度是(logn+200)*n

只是也没办法啦。要期末嘛

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 thei-th leg isli.

Arthur decided to make the table stable and remove some legs. For each of them Arthur determined numberdi — the amount of energy that he spends to remove thei-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 with5 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 integersli (1 ≤ li ≤ 105), whereli is equal to the length of thei-th leg of the table.

The third line of the input contains a sequence of n integersdi (1 ≤ di ≤ 200), wheredi is the number of energy units that Arthur spends on removing thei-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.

Sample test(s)
Input
21 53 2
Output
2
Input
32 4 41 1 1
Output
0
Input
62 2 1 1 3 34 3 5 5 2 1
Output
8

#include#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;map
num;struct Box{ int len,val;}box[100010];bool cmp(Box one,Box two){ return one.len
>n; for(int i=0;i
>box[i].len; for(int i=0;i
>box[i].val; sort(box,box+n,cmp); int l=-1,r=-2,ans=-1; for(int i=0;i
::iterator it=num.end(); int len=j-i,sum=0; while(len>0) { if(it==num.begin()) break; it--; for(int k=0;k
second&&len>0;k++,len--) sum+=it->first; } for(int k=l;k<=r;k++) sum+=box[k].val; ans=max(ans,sum); i=j; break; } int sum=0; for(int i=0;i

转载地址:http://vapjm.baihongyu.com/

你可能感兴趣的文章
JXL GC 问题探讨
查看>>
并发编程四之互斥
查看>>
极速免费-Magento开源产品上传利器magmi
查看>>
magento如何获得产品的属性Minimum Qty Allowed in Shopping Cart
查看>>
FreeMarker循环变量内建函数
查看>>
Python中time模块详解
查看>>
java 的模板方式设计模式
查看>>
跳转到servlet出现java.lang.InstantiationException:
查看>>
RedHat7 配置VNCServer
查看>>
git 回滚版本
查看>>
Nginx反向代理实现会话(session)保持的两种方式
查看>>
Nginx配置指令location匹配符优先级和安全问题
查看>>
sc create 创建启动服务带参数 目录不能有空格
查看>>
Glusterfs初体验
查看>>
Centos搭建SVN服务器三步曲
查看>>
NC-ERP IUFO系统管理要点
查看>>
linux下将文件设置为swap
查看>>
jquery filter()方法
查看>>
make和makefile
查看>>
eclipse git 强制覆盖本地文件
查看>>