由于期末。非常久没刷题了,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
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
#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的更多相关文章

  1. codeforces 557 D. Vitaly and Cycle 组合数学 + 判断二分图

    D. Vitaly and Cycle       time limit per test 1 second memory limit per test 256 megabytes input sta ...

  2. Codeforces Round #557 (Div. 1) 简要题解

    Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...

  3. Codeforces Round #557 题解【更完了】

    Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...

  4. Codeforces Round #557 (Div. 1)

    A.直接做. #include<vector> #include<cstdio> #include<cstring> #include<iostream> ...

  5. 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 ...

  6. Codeforces Round #557 B. Double Matrix

    题面: 传送门 题目描述: 给出两个n*m的矩阵,问:是否能通过交换两个矩阵"对应"位置的元素,使两个矩阵都为"递增"矩阵. "递增"矩阵定 ...

  7. codeforces 557B. Pasha and Tea 解题报告

    题目链接:http://codeforces.com/problemset/problem/557/B 题目意思:有 2n 个茶杯,规定第 i 个茶杯最多只能装 ai 毫升的水.现在给出 w 毫升的水 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 第001弹:Java 中创建对象的4种方式

    Java 是面向对象的语言,不可避免的,“对象”这个概念是 Java 语言的核心部分,这里来简单讨论一下在 Java 中创建一般对象的方法. 总结下来有以下4种创建对象的方法: 使用 new 关键字调 ...

  2. Java众神之路(1)-语言介绍

    Java语言介绍 1.Java的历史 我个人认为,学习一种技术,不止要关注技术本身,也应该去了解一下它的发展史,这一方面是对技术本身的尊重,另一方面也是希望能够通过该技术的发展历史推测出其未来可能的发 ...

  3. matlab 中的删除文件

    Matlab中有两种删除文件的方式: 一种是删除文件     delete()函数      //可以使用help  delete命令查询delete()函数的使用方法 delete('p1.jpg' ...

  4. LA 3905 Meteor 扫描线

    The famous Korean internet company nhn has provided an internet-based photo service which allows The ...

  5. hdu 6021 MG loves string

    MG loves string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others ...

  6. 2018.8.7 Noip2018模拟测试赛(二十)

    日期: 八月七号  总分: 300分  难度: 提高 ~ 省选    得分: 100分(呵呵一笑) 题目列表: T1:SS T2:Tree Game T3:二元运算 赛后反思: Emmmmmm…… 开 ...

  7. 洛谷 P 3379 【模板】最近公共祖先(LCA)

    题目描述 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先. 输入输出格式 输入格式: 第一行包含三个正整数N.M.S,分别表示树的结点个数.询问的个数和树根结点的序号. 接下来N-1行每 ...

  8. Change visual studio 2015 enterprise installation path(转)

    I would like to install VS2015 in a drive different than C:. The problem is that when I run the inst ...

  9. UML学习倒腾记

    先看到http://www.jianshu.com/p/1256e2643923这篇博客,号称21分钟入门uml,也许是我太笨了吧,一下午也没有完全搞定: 使用过atom编辑器,没有完全运行出来结果. ...

  10. 【leetcode】 First Missing Positive

    [LeetCode]First Missing Positive Given an unsorted integer array, find the first missing positive in ...