codeforces Educational Codeforces Round 55 (Rated for Div. 2) C题 C. Multi-Subject Competition

这道题比赛时候没做出来,下来一看才发现是排序傻逼题。

把每个偏好的人做成一个vector,从大到小排序,做一个前缀和。然后将每种人数做一个桶,在桶里装每种科目选择人数为i的时候分数总和。

遍历每一维vector,把各个位置上面的vector加到sum数组中,最后sum数组里面挑出最大值。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> vec[100010];//vector一定要声明类型
ll sum[100010];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int subject,score;
		scanf("%d%d",&subject,&score);
		vec[subject].push_back(score);
	}
	for(int i=1;i<=m;i++)
	{
		sort(vec[i].begin(),vec[i].end(),cmp);
	}
	int maxsize=0;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<vec[i].size();j++)
		{
			   vec[i][j]+=vec[i][j-1];
		}
		maxsize=max((int)vec[i].size(),maxsize);
	}
	ll res=0;
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<vec[i].size();j++)
		{
		   if(vec[i][j]>0)
			  sum[j+1]+=vec[i][j];
		}
	}
	for(int i=1;i<=maxsize;i++)
	{
		//printf("%d ",sum[i]);
		res=max(sum[i],res);
	}
	printf("%lld\n",res);
}

  

原文地址:https://www.cnblogs.com/lishengkangshidatiancai/p/10041607.html

时间: 2024-10-13 00:28:39

codeforces Educational Codeforces Round 55 (Rated for Div. 2) C题 C. Multi-Subject Competition的相关文章

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 74 (Rated for Div. 2)补题

慢慢来. 题目册 题目 A B C D E F G 状态 √ √ √ √ × ? ? //√,×,? 想法 A. Prime Subtraction res tp A 题意:给定\(x,y(x>y)\),问能否将\(x-y\)拆成任意多个质数之和 1.任意大于\(1\)的整数\(k\)都可以用\(2\)与\(3\)的线性表示 证: 若\(k\)是偶数,显然: 若\(k\)是奇数,则\(k\)可以表示成\(k = 3 + 2*k'\),显然: 毕. #include<bits/stdc++.h&

Educational Codeforces Round 55 (Rated for Div. 2) C. Multi-Subject Competition 【vector 预处理优化】

传送门:http://codeforces.com/contest/1082/problem/C C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A multi-subject competition is coming! The competition has mm 

Codeforces 1082 C. Multi-Subject Competition-有点意思 (Educational Codeforces Round 55 (Rated for Div. 2))

C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A multi-subject competition is coming! The competition has mm different subjects participants can choose from.

[Educational Codeforces Round 55 (Rated for Div. 2)][C. Multi-Subject Competition][时间复杂度]

https://codeforc.es/contest/1082/problem/C 题目大意:有m个类型,n个人,每个人有一个所属类型k和一个能力v,要求所选的类型的人个数相等并且使v总和最大(n,m<=1e5) 题解:用vector存下每种类型的各个v并且每种类型根据v按从大到小排序,然后处理出每种类型的前缀和,然后扫每种类型的所有前缀和,如果该类型在i处的前缀和大于0,则相应的ans[i]加上这个类型在i处的前缀和,最后求出max(ans[i])(1<=i<=n)即可. 注意:这题

Codeforces 1082 A. Vasya and Book-题意 (Educational Codeforces Round 55 (Rated for Div. 2))

A. Vasya and Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya is reading a e-book. The file of the book consists of nn pages, numbered from 11 to nn. The screen is currently disp

Codeforces 1082 D. Maximum Diameter Graph-树的直径-最长链-构造题 (Educational Codeforces Round 55 (Rated for Div. 2))

D. Maximum Diameter Graph time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Graph constructive problems are back! This time the graph you are asked to build should match the following proper

Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies

传送门 https://www.cnblogs.com/violet-acmer/p/10035971.html 题意: Vova有n个奖杯,这n个奖杯全部是金奖或银奖,Vova将所有奖杯排成一排,你最多可以交换其中两个奖杯,求最大的连续的金奖杯个数. 题解: 思路: 求出连续的金奖杯位置,找出每两个相邻的连续的金奖杯所能够形成的最大的连续的金奖杯的个数,输出最大值. 相关变量解释: 1 int n; 2 char trophy[maxn]; 3 struct Node 4 { 5 int l,

Educational Codeforces Round 55 (Rated for Div. 2) C. Multi-Subject Competition (实现,贪心,排序)

C. Multi-Subject Competition time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A multi-subject competition is coming! The competition has m different subjects participants can choose from. That'