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 ...
随机推荐
- 离群点检测与序列数据异常检测以及异常检测大杀器-iForest
1. 异常检测简介 异常检测,它的任务是发现与大部分其他对象不同的对象,我们称为异常对象.异常检测算法已经广泛应用于电信.互联网和信用卡的诈骗检测.贷款审批.电子商务.网络入侵和天气预报等领域.这些异 ...
- pip更新及Requirement already up-to-date解决方法
pip更新及Requirement already up-to-date解决方法 文:铁乐与猫 2018-9-11 更新命令 将pip更新到最新版本 python -m pip install --u ...
- Unity Ulua1.03优化记录
现在项目的框架是在2015年设计的,那时候Ulua还处于1.03版本,现在回头再看,Ulua已经迭代到1.25版本,中间引入带有wraper的cstolua,而后转向现有的toLua#版本. 随着版本 ...
- mini2440裸机试炼之—RTC闹钟中断,节拍中断
版权声明:博客地址:http://blog.csdn.net/muyang_ren.源代码能够在我的github上找看看 https://blog.csdn.net/muyang_ren/articl ...
- 一个非常好的php实现手机号归属地查询接口类
前一阵子看到了一个非常好的php手机归属地查询的类,写的很精简,查询也很精确!大致代码是这样的: <?php header("Content-type:text/html;charse ...
- Sysbench-OLTP数据库测试
使用sysbench进行oltp测试之前,需要核对一下sysbench的版本,因为不同版本在使用的参数时,会有一定的差异. mysql dba这本书中的sysbench使用的是0.5的版本,ubunt ...
- k8s调度的亲和性和反亲和性
文章转自 http://ju.outofmemory.cn/entry/278349 https://www.jianshu.com/p/102c4df69af9 RequiredDuringSche ...
- vscode中iframe的使用
vscode中iframe由于某种原因不支持本地页面,比如<iframe src ="index.html" width="300" height=&qu ...
- P2731 骑马修栅栏 欧拉函数
题目背景 Farmer John每年有很多栅栏要修理.他总是骑着马穿过每一个栅栏并修复它破损的地方. 题目描述 John是一个与其他农民一样懒的人.他讨厌骑马,因此从来不两次经过一个栅栏.你必须编一个 ...
- MySQL 基础四 存储过程
-- 定义存储过程 DELIMITER // CREATE PROCEDURE query_student2() BEGIN SELECT * FROM student; END // DELIMIT ...