传送门

文章目录

  • 题意:
  • 思路:

题意:


n≤2e5,m≤n,p≤1e9n\le2e5,m\le n,p\le 1e9n≤2e5,m≤n,p≤1e9

思路:

首先需要发现一些性质,假设preipre_iprei​代表所有mj<im_j< imj​<i的pjp_jpj​和。可以发现,如果我们处理到了人数达到iii才能主动投票的某些人的时候,所有<i<i<i的人无论是被收买来的,还是没有花费任何代价来的,都不需要关心。我们只需要关心所有mj≥im_j\ge imj​≥i的人。如果preipre_iprei​的人数达不到iii,那么我们只能从所有mj≥im_j\ge imj​≥i的人中选出前i−preii-pre_ii−prei​小的人收买他们,才能达到iii的要求,之后才能进行i+1i+1i+1。
当然上面的过程是正着想的,具体的代码可以对mim_imi​开一个桶,倒着来,每次将mj=im_j=imj​=i的pjp_jpj​都加入优先队列中,拿出来即可。
复杂度O(nlogn)O(nlogn)O(nlogn)

// Problem: E1. Voting (Easy Version)
// Contest: Codeforces - Educational Codeforces Round 75 (Rated for Div. 2)
// URL: https://codeforces.com/problemset/problem/1251/E1
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n;
int p[N];
vector<int>v[N];int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);int _; scanf("%d",&_);while(_--) {scanf("%d",&n);for(int i=0;i<=n;i++) v[i].clear();for(int i=1;i<=n;i++) {int x; scanf("%d%d",&x,&p[i]);v[x].pb(p[i]);}int cnt=0,pre=n;LL ans=0;priority_queue<int,vector<int>,greater<int>>q;for(int i=n;i>=1;i--) {pre-=v[i].size();int need=i-pre;for(auto x:v[i]) q.push(x);while(cnt<need) {ans+=q.top(); q.pop();cnt++;}}printf("%lld\n",ans);}return 0;
}
/**/

Educational Codeforces Round 75 (Rated for Div. 2) E2. Voting (Hard Version) 贪心相关推荐

  1. Educational Codeforces Round 75 (Rated for Div. 2) D. Salary Changing 二分 + check

    传送门 文章目录 题意: 思路: 题意: 思路: 直接算不好算,考虑二分这个中位数midmidmid. 考虑如何checkcheckcheck,这个分情况来就好了: (1)mid>a[i].r( ...

  2. Educational Codeforces Round 75 (Rated for Div. 2)

    Preface 我要开始打Codeforces了,这是我的第二场比赛,本来以为可以快速上分的,谁知在pupil的路上越走越远.打算补题补到D题,在三天内完成. 本场战绩: Cost Time: 2 h ...

  3. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

  4. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  5. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

  6. Educational Codeforces Round 37 (Rated for Div. 2) 1

    Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...

  7. Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)

    Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...

  8. Educational Codeforces Round 114 (Rated for Div. 2) D. The Strongest Build 暴力 + bfs

    传送门 文章目录 题意: 思路: 题意: 你有nnn个装备槽,每个槽里面有cic_ici​个力量加成,对于每个槽只能选一个力量加成,现在给你mmm个力量组合[b1,b2,...,bn][b_1,b_2 ...

  9. Educational Codeforces Round 72 (Rated for Div. 2) D. Coloring Edges dfs树/拓扑找环

    传送门 文章目录 题意: 思路: 题意: 给你一张图,你需要给这个图的边染色,保证如果有环那么这个环内边的颜色不全相同,输出染色方案和用的颜色个数. n,m≤5e3n,m\le5e3n,m≤5e3 思 ...

最新文章

  1. Serverless.com CEO首次访华!探讨无服务器技术落地
  2. get event by http request via CL_HTMLB_MANAGER
  3. ***error*** (zip#Browse) unzip not available on your system
  4. C语言 main 函数 - C语言零基础入门教程
  5. OpenVINO 获取计算棒计算结果
  6. 阿里笔试的一道算法题
  7. android中上拉下滑布局,3年以上勿进!最简单的Android自定义ListView下拉刷新与上拉加载,代码直接拿去用~...
  8. 《Redis设计与实现》知识点目录
  9. 国际贸易中的信用证使用
  10. linux gcc编译优化(O0、O1、O2、O3、Os)学习笔记
  11. 记录一下腾讯视频桌面windows客户端面试(一面)
  12. word中设置页眉页脚奇偶页不同,页脚为页码时偶数页不显示一招解决
  13. 各种算法的时间复杂度
  14. 在 Azure ML 上用 .NET 跑机器学习
  15. 阅读笔记 - 20220401
  16. 安卓盒子launcher界面开发之添加自动定位,获取当地天气
  17. ffmpeg读取rtsp并保存到mp4文件
  18. 制造工厂生产线液晶电子看板显示终端
  19. HanLP极致简繁转换详细讲解 1
  20. 代练通 服务器维护,服务器什么毛病?

热门文章

  1. 理科都要学大学计算机吗,女生不适合学理科专业?报考这些理科专业,一毕业就会遭到疯抢!...
  2. arduino代码_纯纯小白开发arduino--我的调试经验
  3. 10个经典的爆炸化学反应,个个都是你惹不起的“暴脾气”
  4. 新天龙八部服务器维护了吗,《新天龙八部》3月11日全服更新维护公告
  5. java 数组长度 可变_java基础之集合长度可变的实现原理
  6. python检验阿姆斯特朗数_python 之九九乘法表,润年,奇偶数,阿姆斯特朗数判断分享...
  7. 服务器运行慢都有哪些问题,服务器数据库的运行速度很慢问题
  8. 广东省计算机应用(2010),2010年广东省高等教育自学考试计算机基础及应用(N)试卷(课程代码.doc...
  9. mysql 碎片率_MySQL数据碎片的整理和分析
  10. java实用教程——组件及事件处理——对话框(颜色对话框,自定义对话框)