Educational Codeforces Round 55 (Rated for Div. 2):C. Multi-Subject Competition
C. Multi-Subject Competition
题目链接:https://codeforces.com/contest/1082/problem/C
题意:
给出n个信息,每个信息包含专业编号以及对应权值,先要求选出一些数量相等的专业(每种专业选的个数相等,不要求每种专业都要选),使对应权值最大。
题解:
一开始想的是枚举选的数量,然后再枚举每种专业从大到小贪心地选,但是时间超了...
其实还有更巧妙地方法,直接考虑每种专业选的个数从1到x对答案的贡献,用一个数组保存这一个贡献就好了。
对于一个专业对答案的贡献用到了最大连续子段和的技巧。
代码如下:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+;
int n,m;
vector <int> vec[N];
int main(){
scanf("%d%d",&n,&m);
int maxn = ;
int ans=;
for(int i=;i<=n;i++){
int s,r;
scanf("%d%d",&s,&r);
vec[s].push_back(r);
int tmp=vec[s].size();
maxn=max(maxn,tmp);
}
for(int i=;i<=m;i++){
sort(vec[i].begin(),vec[i].end());
reverse(vec[i].begin(),vec[i].end());
}
int sum[N]={};
for(int i=;i<=m;i++){
int tot=;
int len=vec[i].size();
for(int j=;j<len;j++){
tot+=vec[i][j];
if(tot>) sum[j+]+=tot;
else tot=;
}
}
for(int i=;i<=maxn;i++) ans=max(ans,sum[i]);
cout<<ans;
return ;
}
Educational Codeforces Round 55 (Rated for Div. 2):C. Multi-Subject Competition的更多相关文章
- Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency
E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...
- Educational Codeforces Round 55 (Rated for Div. 2):D. Maximum Diameter Graph
D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成 ...
- Educational Codeforces Round 55 (Rated for Div. 2)E
题:https://codeforces.com/contest/1082/problem/E 题意:给出n个数和一个数c,只能操作一次将[L,R]之间的数+任意数,问最后该序列中能存在最多多少个c ...
- 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 ...
- Educational Codeforces Round 55 (Rated for Div. 2) A/B/C/D
http://codeforces.com/contest/1082/problem/A WA数发,因为默认为x<y = = 分情况讨论,直达 or x->1->y or x-& ...
- Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies 【贪心 】
传送门:http://codeforces.com/contest/1082/problem/B B. Vova and Trophies time limit per test 2 seconds ...
- 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 ...
- 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 i ...
- Educational Codeforces Round 55 (Rated for Div. 2)
D. Maximum Diameter Graph 题意 给出每个点的最大度,构造直径尽可能长的树 思路 让度数大于$1$的点构成链,考虑是否能在链的两端加度为$1$的点 代码 #include &l ...
随机推荐
- hack游戏攻略(梦之光芒黑客小游戏)
2019.2.11 继续玩~~还是黑客游戏闯关类的 地址:http://monyer.com/game/game1/ 直接查看页面代码: first.php就是了: 查看源代码: 这里尝试输入 两个空 ...
- 配置vue-yarm-PM2工具环境
步骤: 第一步:安装yarn 参考网址:https://yarn.bootcss.com/docs/install.html#linux-tab a.用pm2启动已创建的server.js #pm ...
- hoj第三场G-manhattanp ositioning system
---恢复内容开始--- 一.题意 在二维坐标系内,给定若干个点和目标点距离该点的曼哈顿距离,求是否存在唯一解使得目标点坐标为整数. 二.题解 重新思考题目模型,考虑曼哈顿距离一定时,几何含义为,以给 ...
- C#中Equals和= =(等于号)的比较)(转载)
C#中Equals和= =(等于号)的比较) 相信很多人都搞不清Equals和 = =的区别,只是零星的懂一点,现在就让我带大家来进行一些剖析 一. 值类型的比较 对于值类型来说 ...
- 【jQuery】 资料
[jQuery] 资料 1. 选择器 http://www.w3school.com.cn/jquery/jquery_ref_selectors.asp 2. 事件 http://www.w3sch ...
- ABP官方文档
https://aspnetboilerplate.com/Pages/Documents/Introduction
- Linux复制和移动文件
cp:复制文件和目录 cp /etc/log /mu 把/etc/log复制到/mu目录下 -r:递归复制目录 -f:强制复制目录或文件 -i:交互式 -p:保留源文件或目录的属性 mv:移动或重命名 ...
- Docker安装Zabbix全记录
零.Zabbix架构设计 一.docker安装mysql 查找Docker Hub上的mysql镜像: [root@10e131e69e15 ~]# docker search mysql INDEX ...
- [Java-Idea]解决idea启动项目报错:Unable to open debugger port(127.0.0.1:53046):java.net.SocketException"socket closed
命令行窗口,执行命令:netstat -aon|findstr 9030 查找占用端口的进程 taskkill -f -pid 11331
- MUI scroll 定位问题
做一个微信项目,使用MUI做框架,在使用scroll定位的时候,出现了定位不准确的问题,查询了好多资料,得知他是相对定位.折腾了好久,才搞定,现在做一个笔记. mui('body').on('tap' ...