C. Multi-Subject Competition
链接
[https://codeforces.com/contest/1082/problem/C]
题意
有n个人,m个科目,每个人都有选的科目si,以及他的能力值ri,
规则是每个科目要么选要么不选的,选的那些科目要求人数相同,问你最大能力总和是多少
分析
就先排序,求前缀和,后面就贪心
代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
bool cmp(int a,int b){
return a>b;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n,m;
//freopen("in.txt","r",stdin);
while(cin>>n>>m){
int r,s; vector<int> ve[N]; int sum[N];
for(int i=0;i<n;i++){
cin>>s>>r; ve[s].push_back(r);
}
int ma=0;
for(int i=1;i<=m;i++){
sort(ve[i].begin(),ve[i].end(),cmp); int len=ve[i].size(),cnt=0;
ma=max(ma,len);
for(int j=0;j<len;j++){
cnt+=ve[i][j];
if(cnt>0) sum[j+1]+=cnt;
else break;
}
}
//for(int i=0;i<ve[2].size();i++) cout<<[2][i]<<endl;
int ans=0;
for(int i=1;i<=ma;i++) ans=max(ans,sum[i]);
cout<<ans<<endl;
}
return 0;
}
C. Multi-Subject Competition的更多相关文章
- Codeforces 1082C Multi-Subject Competition 前缀和 A
Codeforces 1082C Multi-Subject Competition https://vjudge.net/problem/CodeForces-1082C 题目: A multi-s ...
- 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 ...
- [AngularFire2] Update multi collections at the same time with FirebaseRef
At some point, you might need to udpate multi collections and those collections should all updated s ...
- 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 inputst ...
- Shiro中的subject.login()
当调用ShiroHandler中的subject.login()的时候,会自动调用Realm中的doGetAuthenticationInfo方法.
- python学习笔记4-redis multi watch实现锁库存
python 关于redis的基本操作网上已经很多了,这里主要介绍点个人觉得有意思的内容1.redis的事务操作以及watch 乐观锁:后面描述2.tornado下异步使用redis的方式 ...
- Elasticsearch——multi termvectors的用法
前一篇已经翻译过termvectors的使用方法了,这对于学习如何使用tf-idf来说是很有帮助的了. 更多内容参考我整理的ELK教程 什么是TF-IDF? 今天早晨起来,看<ES IN ACT ...
- A Regularized Competition Model for Question Diffi culty Estimation in Community Question Answering Services-20160520
1.Information publication:EMNLP 2014 author:Jing Liu(在前一篇sigir基础上,拓展模型的论文) 2.What 衡量CQA中问题的困难程度,提出从两 ...
- redis watch multi exec 关系
EXEC 执行所有事务块内的命令. 假如某个(或某些) key 正处于 WATCH 命令的监视之下,且事务块中有和这个(或这些) key 相关的命令,那么EXEC 命令只在这个(或这些) key 没有 ...
- 使用multi curl进行http并发访问
curl是一款利用URL语法进行文件传输的工具,它支持多种协议,包括FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET等,我们既可以在命令行上使用它,也可以利用 libcur ...
随机推荐
- HDU ACM 1869 六度分离(Floyd)
六度分离 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 【PAT】B1041 考试座位号(15 分)
/* */ #include<stdio.h> #include<algorithm> using namespace std; struct stu{ char number ...
- httpd的一些知识点
一.httpd持久化连接:使用httpd之telnet测试其keepalive连接状态 作用:连接建立后,每个资源获取结束不会断开连接,而继续等待其他资源请求并完成传输. 1.KeepAlive O ...
- Linux系统根据端口号来查看其进程并杀死进程
1.首先是查看某个端口号,(以httpd服务为例) 2.查看此端口下进程以及进程号 3.我们使用awk命令过滤出第二列,即进程号 4.杀死进程 报错的这一行表示,要杀死的进程PID为3754,但是没有 ...
- Ubuntu 16.04 LTS 降级安装GCC 4.8
转载自https://www.linuxidc.com/Linux/2017-03/142299.htm Ubuntu 16.04 LTS 降级安装GCC 4.8 [日期:2017-03-28] 来源 ...
- January 14th, 2018 Week 02nd Sunday
Embrace your life, for we only live once. 拥抱你的生活,因为我们只能活一次. We just live once, so I would rather liv ...
- PHP的curl查看header信息的功能(包括查看返回header和请求header)
PHP的curl功能十分强大,简单点说,就是一个PHP实现浏览器的基础. 最常用的可能就是抓取远程数据或者向远程POST数据.但是在这个过程中,调试时,可能会有查看header的必要. 如下: ech ...
- [luogu 5300][bzoj 5502] [GXOI/GZOI2019] 与或和
题面 思路还是挺容易想的, 只是由于我还是太\(naive\)了一点不会做只会打暴力吧...... 题目要我们求所有子矩阵的\(and\)值之和与\(or\)值之和, 一看之下似乎不好入手, 我们慢慢 ...
- P1004 方格取数-洛谷luogu-dp动态规划
题目描述 设有N \times NN×N的方格图(N \le 9)(N≤9),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字00.如下图所示(见样例): A 0 0 0 0 0 0 0 0 ...
- MATLAB——神经网络构造线性层函数linearlayer
% example5_7.m x=-:; y=*x-; randn(); % 设置种子,便于重复执行 y=y+randn(,length(y))*1.5; % 加入噪声的直线 plot(x,y,'o' ...