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 ...
随机推荐
- 【PAT】B1039 到底买不买(20)(20 分)
/* 琢磨了很久,当时还没做几道题,参考了柳婼的思路 */ #include<stdio.h> #include<string.h> char arr[1000]={'\0'} ...
- Mysql基础之 基础知识解释
Mysql基础知识 RDBMS:关系型数据库管理系统.是将数据组织成相关的行和列的系统 存储过程:是存储在数据库中的一段声明性语句.触发器.java.php等都可以调用其存储过程.早期的mysql版本 ...
- 【18】如何把数据存储到MongoDB数据库
如何把数据存储到MongoDB数据库 时间:2018.10.31 edit by :北鼻 一.mongoDB环境安装 需要使用mongoDB数据库的话需要安装环境, ...
- Vue框架的两种使用方式
1.单页面应用:使用Vue CLI工具生成脚手架,这是最常见的使用方式,简单用模板生成一个HelloWorld Demo,可以学习Vue的SPA项目结构 2.传统多页面应用:通过script引入Vue ...
- Codeforces gym 101343 A. On The Way to Lucky Plaza【概率+逆元+精度问题】
2017 JUST Programming Contest 2.0 题目链接:http://codeforces.com/gym/101343/problem/A A. On The Way to ...
- 迷宫问题 dfs bfs 搜索
定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...
- (14)Python类
- go标准库的学习-strings-字符串操作
参考https://studygolang.com/pkgdoc 导入方式: import "strings" strings包实现了用于操作字符的简单函数. 常用的几个函数: f ...
- mybatis基础系列(三)——动态sql
本文是Mybatis基础系列的第三篇文章,点击下面链接可以查看前面的文章: mybatis基础系列(二)--基础语法.别名.输入映射.输出映射 mybatis基础系列(一)--mybatis入门 动态 ...
- 2-物联网开发标配方案(51单片机程序介绍+WIFI程序介绍)
上一节 https://www.cnblogs.com/yangfengwu/p/9944438.html 购买云服务器安装MQTT就不用说了,以前写过文章介绍 https://www.cnblog ...