codeforces 557 C

因为期末,很久没刷题了,CF一直掉……

这个题其实很简单。。因为做法很容易想到嘛。。

就是枚举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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-11 11:03:59

codeforces 557 C的相关文章

codeforces 557 E Ann and Half-Palindrome

题意是要求出一个串的第k大的半回文子串 半回文串的定义是:若一个串其实位置为1,那么当所有奇数位i,且i<=(s.length+1/2),满足s[i]=s[s.length-i+1]的时候, 那么这个串就是半回文串. 作法就是,把这个串的所有半回文子串建成一个字典树,然后查第k大就好了 #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdli

codeforces 557

 /*A没啥说的,,先都满足最小然后优先满足前面的*/ #include <iostream> #include<bits/stdc++.h> using namespace std; int main() { int m; scanf("%d",&m); int a[5][2]; int b[5]; int i; int minn=0; for(i=0;i<3;i++) { scanf("%d %d",&a[i][

Codeforces Round #557 B. Double Matrix

题面: 传送门 题目描述: 给出两个n*m的矩阵,问:是否能通过交换两个矩阵“对应”位置的元素,使两个矩阵都为“递增”矩阵. “递增”矩阵定义:每行和每列都要“递增”. 题目分析: 这道题就是个贪心水题,但是我刚开始就是胡思乱想,思路根本不对,再加上放假后的懒惰,就...进入正题: 我们可以想出这样一种贪心策略:让前面的值尽可能小,后面才有更大的机会成为“递增”矩阵.我们根据这个贪心策略,可以推出一些东西: 注:下面的a,b是两个题目给出的矩阵 假设我要让a(i, j)尽可能小,也就是:如果a(

codeforces 557B. Pasha and Tea 解题报告

题目链接:http://codeforces.com/problemset/problem/557/B 题目意思:有 2n 个茶杯,规定第 i 个茶杯最多只能装 ai 毫升的水.现在给出 w 毫升的水,需要把这w毫升(可以不用光)的水倒入到这 2n 个茶杯中,使得分给n个男的每个水杯的水恰好是n个女的2倍(注意,n个男的水杯装的水是一样的,n 个女也是).现在问的是,怎样使得2n个杯装的水最多,求出这个值. ********************************************

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store