链接

[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的更多相关文章

  1. Codeforces 1082C Multi-Subject Competition 前缀和 A

    Codeforces 1082C Multi-Subject Competition https://vjudge.net/problem/CodeForces-1082C 题目: A multi-s ...

  2. 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 ...

  3. [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 ...

  4. 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 ...

  5. Shiro中的subject.login()

    当调用ShiroHandler中的subject.login()的时候,会自动调用Realm中的doGetAuthenticationInfo方法.

  6. python学习笔记4-redis multi watch实现锁库存

    python 关于redis的基本操作网上已经很多了,这里主要介绍点个人觉得有意思的内容1.redis的事务操作以及watch 乐观锁:后面描述2.tornado下异步使用redis的方式       ...

  7. Elasticsearch——multi termvectors的用法

    前一篇已经翻译过termvectors的使用方法了,这对于学习如何使用tf-idf来说是很有帮助的了. 更多内容参考我整理的ELK教程 什么是TF-IDF? 今天早晨起来,看<ES IN ACT ...

  8. 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中问题的困难程度,提出从两 ...

  9. redis watch multi exec 关系

    EXEC 执行所有事务块内的命令. 假如某个(或某些) key 正处于 WATCH 命令的监视之下,且事务块中有和这个(或这些) key 相关的命令,那么EXEC 命令只在这个(或这些) key 没有 ...

  10. 使用multi curl进行http并发访问

    curl是一款利用URL语法进行文件传输的工具,它支持多种协议,包括FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET等,我们既可以在命令行上使用它,也可以利用 libcur ...

随机推荐

  1. .net core 导出Excel(epplus 创建excel )

    [Route("getopenfrequencyexcel")] [HttpGet] public IActionResult GetOpenFrequencyExcel(int ...

  2. Nginx安装成Windows服务

    因为有项目使用Nginx来做负载均衡,但是Nginx的Windows版本是不提供安装成服务的,所以服务器重启后Nginx并不会伴随启动和恢复.网上查了下,这里记录下解决方法,防止遗忘. 第一步:下载W ...

  3. 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] 来源 ...

  4. kafka集群环境搭建(Linux)

    一.准备工作 centos6.8和jvm需要准备64位的,如果为32位,服务启动的时候报java.lang.OutOfMemoryError: Map failed 的错误. 链接:http://pa ...

  5. 在Oracle中使用Guid

    sys_guid()  -  唯一索引 在Oracle中可以用SYS_GUID()来生成一个guid,相当于msSql中的newid(). 在Oracle9i和Oracle 10g 里SYS_GUID ...

  6. Git提交新项目

    Github或者码云上新建项目 $ git init $ git add * $ git remote add origin https://gitee.com/demo/demo.git $ git ...

  7. Excel中row函数的使用方法

    1.row函数的含义 1 row函数的含义 返回所选择的某一个单元格的行数. END 2.row函数的语法格式 1 row函数的语法格式 =row(reference) 如果省略reference,则 ...

  8. gitlab11.5.4 配置邮件提醒

    gitlab 配置邮件提醒 gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.qiye.163. ...

  9. Domain Adaptation (3)论文翻译

    Abstract The recent success of deep neural networks relies on massive amounts of labeled data. For a ...

  10. SQL 公用表达式CTE

    一 基本用法 with mywith as(select * from Student ) select * from mywith 二 递归调用 with mywith as( select ID, ...