codeforces 557 C
由于期末。非常久没刷题了,CF一直掉……
这个题事实上非常简单。
。由于做法非常easy想到嘛。。
就是枚举max=x时,最大能保留多少价值。不断更新ans,
结果就是全部价值和减去ans就好
因为最大可以保留的长度是199+200,所以当max=x时。算最大能保留多少价值,
也是一个循环算出当前长度比x小的那个桌子角的最大的那几个价值之和保留即可了,
这里写的比較绕。。反正看看代码一下就懂了。。。
维护一个map即可了
比赛的时候,由于好久没刷题了。一直没想清楚,一直到比赛结束前还剩下十分钟才恍然大悟。
。
复杂度是(logn+200)*n
只是也没办法啦。要期末嘛
1 second
256 megabytes
standard input
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.
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.
Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.
2
1 5
3 2
2
3
2 4 4
1 1 1
0
6
2 2 1 1 3 3
4 3 5 5 2 1
8
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
map<int,int>num;
struct Box
{
int len,val;
}box[100010];
bool cmp(Box one,Box two)
{
return one.len<two.len;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>box[i].len;
for(int i=0;i<n;i++)
cin>>box[i].val;
sort(box,box+n,cmp);
int l=-1,r=-2,ans=-1;
for(int i=0;i<n;i++)
for(int j=i;j<n;j++)
if(box[j+1].len!=box[i].len)
{
for(int k=l;k<=r;k++)
num[box[k].val]++;
l=i;r=j;
map<int,int>::iterator it=num.end();
int len=j-i,sum=0;
while(len>0)
{
if(it==num.begin())
break;
it--;
for(int k=0;k<it->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<n;i++)
sum+=box[i].val;
cout<<sum-ans;
}
codeforces 557 C的更多相关文章
- codeforces 557 D. Vitaly and Cycle 组合数学 + 判断二分图
D. Vitaly and Cycle time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #557 题解【更完了】
Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...
- Codeforces Round #557 (Div. 1)
A.直接做. #include<vector> #include<cstdio> #include<cstring> #include<iostream> ...
- Codeforces Round #557 Div. 1 based on Forethought Future Cup - Final Round
A:开场就读错题.读对了之后也没啥好说的. #include<bits/stdc++.h> using namespace std; #define ll long long #defin ...
- Codeforces Round #557 B. Double Matrix
题面: 传送门 题目描述: 给出两个n*m的矩阵,问:是否能通过交换两个矩阵"对应"位置的元素,使两个矩阵都为"递增"矩阵. "递增"矩阵定 ...
- codeforces 557B. Pasha and Tea 解题报告
题目链接:http://codeforces.com/problemset/problem/557/B 题目意思:有 2n 个茶杯,规定第 i 个茶杯最多只能装 ai 毫升的水.现在给出 w 毫升的水 ...
- Codeforces Round #311 (Div. 2) E. Ann and Half-Palindrome 字典树/半回文串
E. Ann and Half-Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- Codeforces Round #311 (Div. 2) D. Vitaly and Cycle 图论
D. Vitaly and Cycle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/p ...
随机推荐
- 【Luogu】P4363一双木棋(状压爆搜)
题目链接 唉,只有AC了这道题才会感叹考场上没有想出解法的我是多么智障. 我甚至连任何想法都没有. 天啊我当时到底在想些什么. AC这道题我就能进前15了诶. 我们发现只要确定了轮廓线那么此时的状态就 ...
- [LOJ#525]「LibreOJ β Round #4」多项式
[LOJ#525]「LibreOJ β Round #4」多项式 试题描述 给定一个正整数 k,你需要寻找一个系数均为 0 到 k−1 之间的非零多项式 f(x),满足对于任意整数 x 均有 f(x) ...
- 答题小程序开发之socket编程 微信小程序答题 直播答题开发 直播弹幕使用web socket编程
最近有一个项目很火,那就是直播答题的,接到公司的这个任务,开发直播答题的聊天室功能.在线的人相互聊天.之前做过类似的,当时都是使用的ajax轮询的,这种非常的耗费服务器.所以这次就开始使用socket ...
- 关于后台返回excel文件的问题
一般情况ajax请求只能获取解析非流文件类型,而excel是流文件类型,这个时候获取到的数据会是一串乱码的字符串 想要下载这个excel文件,通过form表单模拟的方式可以解决 var form = ...
- scss 侧边栏_图片
html <!doctype html><html lang="zh-CN"><head> <meta charset="UTF ...
- linux环境内存分配原理 mallocinfo【转】
转自:http://www.cnblogs.com/dongzhiquan/p/5621906.html Linux的虚拟内存管理有几个关键概念: Linux 虚拟地址空间如何分布?malloc和fr ...
- 标准C程序设计七---103
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- Linux spi驱动分析(二)----SPI核心(bus、device_driver和device)
一.spi总线注册 这里所说的SPI核心,就是指/drivers/spi/目录下spi.c文件中提供给其他文件的函数,首先看下spi核心的初始化函数spi_init(void).程序如下: 点击(此处 ...
- unity3d的模型规范
1.不能存在单独的点和面,重复的面和点,不能被玩家所看到的模型也不必制作. 2.贴图要保证始终是2的倍数,但不必为正方形. 3.移动平台,如IP4,应该每个模型一般不超过300-1500个面,同屏不应 ...
- 用Linux完成Oracle自动物理备份
https://blog.csdn.net/24024846/article/details/115292