Educational Codeforces Round 108 (Div. 2), C map套vector存储
地址 Problem - C - Codeforces
题目
题意
一个学校有n个人参加比赛,他们分别属于ui队,每个人的能力值为si
当每个队需要1~n个人的时候,这个学校能参加的人的能力值和最大为多少
解析
map<int,vector<int>>存储不会爆
每一队直接处理出队伍人数为1~n时的能力值最大和,这样不会超时,看代码
代码
#include <iostream>
#include <algorithm>
#include <vector>
#include <map> using namespace std; typedef long long LL;
const int N = 2e5+10; int b[N],c[N];
int main()
{
int t;
cin >> t;
while(t --)
{
int n;
scanf("%d", &n);
map<int,vector<LL>> a;//存第二波输入 for(int i = 1; i <= n; i ++) scanf("%d", &b[i]); //存所属队
for(int i = 1; i <= n; i ++){
int x;
scanf("%d", &x);
a[b[i]].push_back(x);
} vector<LL> res(n+1);//存结果
for(auto p1:a)//遍历每一队
{
vector<LL> &p = p1.second;
sort(p.begin(), p.end()); int len = p.size(); for(int i = 1; i < len; ++i)
p[i] += p[i-1]; for(int i = 1; i <= len; i ++)
res[i]+=p[len-1]-((len%i)?p[len%i-1]:0LL);//把这一队的算出来
}
for(int i = 1; i <= n; i ++)
cout << res[i] << ' ';
puts(""); }
return 0;
}
Educational Codeforces Round 108 (Div. 2), C map套vector存储的更多相关文章
- 组合数学题 Codeforces Round #108 (Div. 2) C. Pocket Book
题目传送门 /* 题意:每一次任选i,j行字符串进行任意长度前缀交换,然后不断重复这个过程,问在过程中,第一行字符串不同的个数 组合数学题:每一列不同的字母都有可能到第一行,所以每列的可能值相乘取模就 ...
- Codeforces Round #108 (Div. 2)
Codeforces Round #108 (Div. 2) C. Pocket Book 题意 给定\(N(N \le 100)\)个字符串,每个字符串长为\(M(M \le 100)\). 每次选 ...
- Educational Codeforces Round 84 (Div. 2)
Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...
- Educational Codeforces Round 62 Div. 2
突然发现上一场edu忘记写了( A:签到. #include<iostream> #include<cstdio> #include<cmath> #include ...
- Educational Codeforces Round 47 (Div 2) (A~G)
目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ...
- Educational Codeforces Round 46 (Div 2) (A~G)
目录 Codeforces 1000 A.Codehorses T-shirts B.Light It Up C.Covered Points Count(差分) D.Yet Another Prob ...
- Educational Codeforces Round 58 Div. 2 自闭记
明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...
- Educational Codeforces Round 45 (Div 2) (A~G)
目录 Codeforces 990 A.Commentary Boxes B.Micro-World C.Bracket Sequences Concatenation Problem D.Graph ...
- Educational Codeforces Round 85 (Div. 2)
题目链接:https://codeforces.com/contest/1334 A. Level Statistics 题意 一个关卡有玩家的尝试次数和通关次数,按时间顺序给出一个玩家 $n$ 个时 ...
随机推荐
- Docker——run指令中-it与-d的关系
建立相关的测试容器 #1.只有-d [root@iZwz908j8pbqd86doyrez5Z test]# docker run -d -p 8081:8080 tomcat:9.0 #2.只有-i ...
- python单ip端口扫描器
from socket import * import threading #导入线程相关模块 # qianxiao996精心制作 #博客地址:https://blog.csdn.net/qq_363 ...
- 配置文件 /etc/profile出错导致ls,vi不能用
配置文件 /etc/profile出错导致ls,vi不能用 关于 Linux 的配置文件 /etc/profile 路径出错后相关的命令失效解决方式(如:ls,vi不能用) 一般我记得vi是在 ...
- loj2985「WC2019」I 君的商店(二分,思维)
loj2985「WC2019」I 君的商店(二分,思维) loj Luogu 题解时间 真的有点猛的思维题. 首先有一个十分简单的思路: 花费 $ 2N $ 确定一个为 $ 1 $ 的数. 之后每次随 ...
- 羽夏看Win系统内核——内存管理篇
写在前面 此系列是本人一个字一个字码出来的,包括示例和实验截图.由于系统内核的复杂性,故可能有错误或者不全面的地方,如有错误,欢迎批评指正,本教程将会长期更新. 如有好的建议,欢迎反馈.码字不易, ...
- BUU findkey
定位关键函数 跟入flag找到问题位置 两行一样的代码,nop掉第二行,按p生成函数 代码审计 int __userpurge sub_4018C4@<eax>(int a1@<eb ...
- memcached 的 cache 机制是怎样的?
Memcached 主要的 cache 机制是 LRU(最近最少用)算法+超时失效.当您存 数据到 memcached 中,可以指定该数据在缓存中可以呆多久 Which is forever, or ...
- 什么是 Spring 配置文件?
Spring 配置文件是 XML 文件.该文件主要包含类信息.它描述了这些类是如何 配置以及相互引入的.但是,XML 配置文件冗长且更加干净.如果没有正确规划 和编写,那么在大项目中管理变得非常困难.
- Flutter入门教程(四)第一个flutter项目解析
一.创建一个Flutter工程 1.1 命令行创建 首先我们找一个空目录用来专门存放flutter项目,然后在路径中直接输入cmd: 使用 flutter create <projectname ...
- 使用Google Closure Compiler高级压缩Javascript代码
背景 前端开发中,特别是移动端,Javascript代码压缩已经成为上线必备条件. 如今主流的Js代码压缩工具主要有: 1)Uglify http://lisperator.net/uglifyjs/ ...