Codeforces 1082C Multi-Subject Competition(前缀+思维)
题目链接:Multi-Subject Competition
题意:给定n名选手,每名选手都有唯一选择的科目si和对应的能力水平。并且给定科目数量为m。求选定若干个科目,并且每个科目参与选手数量相同的情况下的最大能力水平。
题解:每位选手扔到对应的科目里面,从1-m遍历科目,能力值排序下,维护下能力值和,大于0就给到当前位置人数答案加上该值,否则跳出(给负价值是没有意义的),最后遍历一遍人数对应的价值,拿最大的即可。
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; const int N=1e5+;
int ans[N];
vector <int> v[N]; int main(){
int n,m,s,r,mx=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%d%d",&s,&r);
v[s].push_back(r);
}
for(int i=;i<=m;i++){
int sum=,sz=v[i].size();
sort(v[i].begin(),v[i].end());
mx=max(mx,sz);
for(int j=sz-;j>=;j--){
sum+=v[i][j];
if(sum>=) ans[sz-j]+=sum;
else break;
}
}
int res=;
for(int i=;i<=mx;i++) res=max(res,ans[i]);
printf("%d\n",res);
return ;
}
Codeforces 1082C 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 30 B【前缀和+思维/经典原题】
B. Balanced Substring time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #304 (Div. 2) D 思维/数学/质因子/打表/前缀和/记忆化
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces 1132C - Painting the Fence - [前缀和优化]
题目链接:https://codeforces.com/contest/1132/problem/C 题意: 栅栏有 $n$ 个节,有 $q$ 个人可以雇佣来涂栅栏,第 $i$ 个人可以涂第 $l_i ...
- codeforces C. Vasya And The Mushrooms (思维+模拟)
题意:给定一个2*n的矩形方格,每个格子有一个权值,从(0,0)开始出发,要求遍历完整个网格(不能重复走一个格子),求最大权值和,(权值和是按照step*w累加,step步数从0开始). 转载: 题解 ...
- Codeforces 305B:Continued Fractions(思维+gcd)
http://codeforces.com/problemset/problem/305/B 题意:就是判断 p / q 等不等于那条式子算出来的值. 思路:一开始看到 1e18 的数据想了好久还是不 ...
- codeforces 876 F. High Cry(思维)
题目链接:http://codeforces.com/contest/876/problem/F 题解:一道简单的思维题,知道最多一共有n*(n+1)/2种组合,不用直接找答案直接用总的组合数减去不符 ...
随机推荐
- 仿9GAG制作过程(二)
有话要说: 这次准备讲述用python爬虫以及将爬来的数据存到MySQL数据库的过程,爬的是煎蛋网的无聊图. 成果: 准备: 下载了python3.7并配置好了环境变量 下载了PyCharm作为开发p ...
- Yii2.0调用sql server存储过程并获取返回值
1.首先展示创建sql server存储过程的语句,创建一个简单的存储过程,测试用. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE P ...
- 一文把samba相关的都说清楚
1.前言 samba源码都一样,配置也也一样,各个不同linux版本,唯一不同的是对服务的启动方式不同.下面以ubuntu14.4为例,说明. 2. 安装samba samba的安装,可以源码安装,大 ...
- python之生成随机密码
https://www.cnblogs.com/evablogs/p/7096583.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #!/usr/bin/py ...
- Python面试常见的问题
So if you are looking forward to a Python Interview, here are some most probable questions to be ask ...
- Django REST framework基础:解析器和渲染器
解析器 解析器的作用 解析器的作用就是服务端接收客户端传过来的数据,把数据解析成自己可以处理的数据.本质就是对请求体中的数据进行解析. 在了解解析器之前,我们要先知道Accept以及ContentTy ...
- Hadoop Compatibility in Flink
18 Nov 2014 by Fabian Hüske (@fhueske) Apache Hadoop is an industry standard for scalable analytical ...
- git -分支管理(创建、推送、删除)
分支创建并推送: 1.查看当前所有分支,当前分支前面会标出一个*号 git branch -a 2.新建分支 git branch android_O 3.切换到新分支 git checkout an ...
- day20-多并发编程基础(一)
重新写一下吧,系统奔溃了,以前写的完全没了,悲催,今日主要写进程 1. 进程的理论知识 2. python中的进程操作 开始今日份整理,加油,你是最胖的!!! 1. 进程的理论知识 1.1 操作系统的 ...
- Spring Security(三十二):10. Core Services
Now that we have a high-level overview of the Spring Security architecture and its core classes, let ...